Create a Multiselect Lookup Control on a Simple Form & Dialog Form
Example: Company Info (Legal Entity) list selection on Purchase order.
ON FORM:
Steps:
1. Create a New String field (String size: based on your requirement) in PurchTable - Table Extension
2. Drag and Drop this field into PurchTable - Form Extension from PurchTable Data source.
3. Create one Simple Query for Company Info Table. (Ex: LegalEntityQueryForFilter)
3. Create a new Extension class for PurchTable form and write some user defined class and add 2 extra - event handler methods (On Initialized the form and On Modified the PurchTable Data Source > Newly created string field): Sample codes on below:
[ExtensionOf(formstr(PurchTable))]
final class PurchTable_YourModelName_Extension
{
public static SysLookupMultiSelectCtrl legalEntityListMultiSelectCtrl;
public Query buildDocuTypeQuery()
{
Query legalEntityQry = new Query(queryStr(LegalEntityQueryForFilter));
return legalEntityQry;
}
public SysLookupMultiSelectCtrl parmSysLookupMultiSelectCtrl(SysLookupMultiSelectCtrl _legalEntityListMultiSelectCtrl = legalEntityListMultiSelectCtrl)
{
legalEntityListMultiSelectCtrl = _legalEntityListMultiSelectCtrl;
return legalEntityListMultiSelectCtrl;
}
container getSelectedLegalEntities(str _legalEntitiesStr)
{
CompanyInfo companyInfoTable;
container tmpValues, conIds, conName;
int idx;
if (_legalEntitiesStr)
{
tmpValues = str2con(_legalEntitiesStr, ';');
}
for (idx = 1; idx <= conLen(tmpValues); idx++)
{
companyInfoTable = CompanyInfo::findDataArea(conPeek(tmpValues, idx));
conIds += companyInfoTable.RecId;
conName += companyInfoTable.DataArea;
}
return [conIds, conName, conIds];
}
// copy OnModified Event handler form PurchTableForm Extension > Data source > select the newly created field.
[FormDataFieldEventHandler(formDataFieldStr(IPurchTable, PurchTable, NewStringField), FormDataFieldEventType::Modified)]
public static void PurchTable_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormRun formRun = sender.datasource().formRun();
SysLookupMultiSelectCtrl companyMultiSelectCtrl = formRun.parmSysLookupMultiSelectCtrl();
PurchTable PurchTableLocal = formRun.dataSource(FormDataSourceStr(PurchTable, PurchTable )).cursor() as PurchTable;
PurchTableLocal.NewStringField = con2Str(companyMultiSelectCtrl.getSelectedFieldValues(), ';');
}
[FormEventHandler(formStr(PurchTable), FormEventType::Initialized)]
public static void PurchTable_OnInitialized(xFormRun sender, FormEventArgs e)
{
FormRun formRun = sender.datasource().formRun();
Query legalEntityQry = formRun.buildDocuTypeQuery();
FormStringControl newFilednameObject = formRun.design().controlName('PurchTable_NewfieldForLegalEntityList');
PurchTable PurchTableLocal = formRun.dataSource(FormDataSourceStr(PurchTable, PurchTable )).cursor() as PurchTable;
legalEntityListMultiSelectCtrl = SysLookupMultiSelectCtrl::construct(formRun,
newFilednameObject ,
querystr(legalEntityQry ),
false,
[tableNum(PurchTable), fieldNum(PurchTable, NewfieldForLegalEntityList)]);
legalEntityListMultiSelectCtrl.refreshQuery(legalEntityQry);
legalEntityListMultiSelectCtrl.set(formRun.getSelectedLegalEntities(PurchTable.NewfieldForLegalEntityList));
formRun.parmSysLookupMultiSelectCtrl(legalEntityListMultiSelectCtrl);
}
----------------------------------
ON DIALOG FORM:
Steps:
1. Create Contract Class or Extension of standard contract class and add this mehod - Parm List of legal entities.
public List selectedEntities;
[ DataMemberAttribute('selectedEntities'),
SysOperationDisplayOrderAttribute('101'),
SysOperationGroupMemberAttribute('ProcessIdentifierGroup'),
AifCollectionTypeAttribute('selectedEntities', Types::String),
SysOperationLabelAttribute(literalStr("@SYS303247"))
]
public List parmSelectedLegalEntities(List _selectedEntities = selectedEntities)
{
selectedEntities = _selectedEntities;
return selectedEntities;
}
2. Create UI Builder Class or Extension of standard UI Builder class and Register lookup method.
Example:
[ExtensionOf(classStr(StandardClassUIBuilder))]
final class StandardClassUIBuilder_OurModel_Extension
{
public DialogField availableCompanies;
public DialogField exchangeRateType;
public StandardContract contract; // above created contract or base contract class name
public void postBuild()
{
boolean mustSkipNext = true;
//DialogField reportIdFieldloc = this.reportIdField;
//DialogField runInBundleloc = this.runInBundle;
try
{
if (mustSkipNext)
{
throw Exception::UpdateConflict;
}
next postBuild();
}
catch (Exception::UpdateConflict)
{
//standardcode
// if require check with company info table buffer find method and set empty value.
reportIdField.value('');
runInBundle.visible(true);
contract = this.dataContractObject() as aboveContractClassName;
availableCompanies = this.bindInfo().getDialogField(contract, methodStr(aboveContractClassName, parmSelectedLegalEntities));
availableCompanies.lookupButton(FormLookupButton::Always);
}
}
public void postRun()
{
boolean mustSkipNext = true;
try
{
if (mustSkipNext)
{
throw Exception::UpdateConflict;
}
next postRun();
}
catch (Exception::UpdateConflict)
{
Query query = new Query();
QueryBuildDataSource qbdsLegalEntity = query.addDataSource(tablenum(CompanyInfo));
qbdsLegalEntity.fields().addField(fieldNum(CompanyInfo, DataArea));
qbdsLegalEntity.fields().addField(fieldNum(CompanyInfo, Name));
container selectedFields = [tableNum(CompanyInfo), fieldNum(CompanyInfo, DataArea)];
SysLookupMultiSelectCtrl::constructWithQuery(this.dialog().dialogForm().formRun(), availableCompanies.control(), query, false, selectedFields);
}
}
}
No comments:
Post a Comment