Rule Combo of SQL table read code Example
  • 12 Oct 2021
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Rule Combo of SQL table read code Example

  • Dark
    Light

Article summary

Rule Combo

To build a Rule Combo, in order to list the valid valued in a combo list, you do the following:

  • You extend AbstractComboRule
  • You create a default blank entry
  • You build up the content, in this example via a SQL against the MITWHL table
  • Finally you add the values to the rendererModel


public class ReceivingWarehouseComboRule extends AbstractComboRule {

public void completeCombo(RendererModel rendererModel,

            ProcessData processData, MapData data, DataInstance dataInstance,

            String simpleMOdelId, String metadataId, String tableName,

            String aliasName, String columnName, int row, Element elmComboData,

            String displayMode) {


        SessionValues sessionValues = dataInstance.getComplexModelInstance().getSessionValues();

        DataTypeHandler dataTypeHandler = dataInstance.getComplexModelInstance().getDataTypeHandler();

        Element elmValues = rendererModel.addComboValues(elmComboData, displayMode, row);

        

        //Add default entry

        rendererModel.addComboValue(elmValues, "", "", "");

        

        SqlResult resMITWHL = null;

        try {

            SelectStatement selMITWHL = new SelectStatement(RepositoryUtil.getTable(MOVEX, "MITWHL"), sessionValues, dataTypeHandler);

            selMITWHL.initWhere();

            selMITWHL.addSelectColumn("MWWHLO");

            selMITWHL.addSelectColumn("MWWHNM");

            SqlWhereGroup mWWHTY = selMITWHL.createWhereGroup(SqlWhereGroup.BINDER_AND); // MWWHTY 1 or 2

            SqlWhereGroup mWWHTY1 = selMITWHL.createWhereGroup(mWWHTY, SqlWhereGroup.BINDER_OR);

            selMITWHL.addWhere(mWWHTY1, "MWWHTY", SqlParameter.EQ, CustConstants.WAREHOUSE_TYPE_DC);

            SqlWhereGroup mWWHTY2 = selMITWHL.createWhereGroup(mWWHTY, SqlWhereGroup.BINDER_OR);

            selMITWHL.addWhere(mWWHTY2, "MWWHTY", SqlParameter.EQ, CustConstants.WAREHOUSE_TYPE_PRODUCTION);

            resMITWHL = selMITWHL.execute();

            while (resMITWHL.next()) {

                String value = resMITWHL.getData("MWWHLO");

                String displayValue = resMITWHL.getData("MWWHLO");

                String descr = resMITWHL.getData("MWWHNM");

                rendererModel.addComboValue(elmValues, value, displayValue, descr);

            }

        } catch (SQLException sqlE) {

            logger.error("Failed to get reference", sqlE);

            return;

        } finally {

            if (resMITWHL != null) {

                resMITWHL.close();

            }

        }

    }








Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.