Announcements
Hi,
I have this lookup code:
////// /// /// /// [FormControlEventHandler(formControlStr(CaseDetailCreate, AAWorker), FormControlEventType::Lookup)] public static void AAWorker_OnLookup(FormControl sender, FormControlEventArgs e) { FormStringControl customerContract = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, AACustomerContract)) as FormStringControl; if(customerContract.text() != '') { SysLookupMultiSelectCtrl multiSelectCtrl; Query query = new Query(); QueryBuildDataSource qbds = query.addDataSource(tableNum(ResourceView)); QueryBuildDataSource qbds1 = qbds.addDataSource(tableNum(PROJVALEMPLPROJSETUP)); Qbds1.joinMode(JoinMode::InnerJoin); Qbds1.addLink(fieldNum(ResourceView, RecId), fieldNum(PROJVALEMPLPROJSETUP, Resource)); QueryBuildDataSource qbds2 = qbds1.addDataSource(tableNum(AATable1)); qbds2.joinMode(JoinMode::InnerJoin); qbds2.addLink(fieldNum(PROJVALEMPLPROJSETUP, ProjId), fieldNum(AATable1, OrderNumber)); qbds2.addRange(fieldNum(AATable1, OrderNumber)).value(queryValue(customerContract.text())); qbds.addSelectionField(FieldNum(ResourceView, ResourceId)); qbds.addSelectionField(FieldNum(ResourceView, Name)); multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query); } else { SysLookupMultiSelectCtrl multiSelectCtrl; Query query = new Query(); QueryBuildDataSource qbds = query.addDataSource(tableNum(HcmWorkerDetailsView)); qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, PersonnelNumber)); qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, Name)); multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query); } }
Then the only work around will be creating view with the required tables and in the view fields add only the fields you want in the lookup.
You can use that view as a datasource in the lookup method.
Thanks,
Girish S.
Hi Girish,
yes selection field doesn't work because this is the query it returns for two dataSources: -- as you can see it returned the 2 selected fields i chose for the first dataSource but it returned all fields for the the other dataSource, maybe if there is a way to say addSeletcionField(null) for other dataSources then it might work
{Query object 4fb3a510: SELECT ResourceId, Name FROM ResourceView(ResourceView_1)
JOIN GroupId, Projid, Resource, dataAreaId, recVersion, Partition, RecId FROM ProjValEmplProjSetup(ProjValEmplProjSetup_1)
ON ResourceView.RecId = ProjValEmplProjSetup.Resource}
As for the new way you suggested: it's still not workingcontainer selectedFields = [tableNum(ResourceView),fieldnum(ResourceView,ResourceId),fieldnum(ResourceView,Name)];
multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, selectedFields);
it returned un-needed fields:
Also would you mind looking at this question: it's related to this one
community.dynamics.com/.../lookup-event-handler-method-is-not-being-called-more-than-once
Edited the code. You can initialize container and add fields to that.
Thanks,
Girish S.
Yo already said that adding selection field doesn't work. That's why I have given an alternate suggestion.
Try the below code.
container selectedFields = [tableNum(ResourceView),fieldnum(ResourceView,ResourceId),fieldnum(ResourceView,Name)]; multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, selectedFields);
Thanks,
Girish S.
Hi Girish,
So you don't want me to use add selection field, right?
can you give me the syntax exactly for multiple fields as i'm getting errors on it
multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, [(tableNum(ResourceView), fieldNum(ResourceView,ResourceId)), (tableNum(ResourceView), fieldNum(ResourceView,Name)));
here's what i did:
[FormControlEventHandler(formControlStr(CaseDetailCreate, AAWorker), FormControlEventType::Lookup)] public static void AAWorker_OnLookup(FormControl sender, FormControlEventArgs e) { FormStringControl customerContract = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, AACustomerContract)) as FormStringControl; SysLookupMultiSelectCtrl multiSelectCtrl; Query query = new Query(); QueryBuildDataSource qbds = query.addDataSource(tableNum(ResourceView)); QueryBuildDataSource qbds1 = qbds.addDataSource(tableNum(PROJVALEMPLPROJSETUP)); qbds1.joinMode(JoinMode::InnerJoin); qbds1.addLink(fieldNum(ResourceView, RecId), fieldNum(PROJVALEMPLPROJSETUP, Resource)); QueryBuildDataSource qbds2 = qbds1.addDataSource(tableNum(Table1)); qbds2.joinMode(JoinMode::InnerJoin); qbds2.addLink(fieldNum(PROJVALEMPLPROJSETUP, ProjId), fieldNum(Table1, OrderNumber)); qbds2.addRange(fieldNum(Table1, OrderNumber)).value(queryValue(customerContract.text())); //qbds.addSelectionField(FieldNum(ResourceView, ResourceId)); //qbds.addSelectionField(FieldNum(ResourceView, Name)); multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, [(tableNum(ResourceView), fieldNum(ResourceView,ResourceId)), (tableNum(ResourceView), fieldNum(ResourceView,Name))]); FormRun formRun = sender.formRun(); formRun.AAMultiSelectCtrl(multiSelectCtrl); }
SysLookupMultiSelectCtrl::constructQuery arguments takes the container as parameter for showing fields in the lookup. Try passing the required fields to that and check.
multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, [tableNum(TableName), fieldNum(TableName,FieldName)]));
Thanks,
Girish S.
Hi Girish,
How about the extra fields appearing in the lookup?
even though i specified only 2 fields using addSelectionField but alot are appearing as i described in previous comments
Hi IntegrationBeginner,
If you declare the SysLookupMultiSelectCtrl multiSelectCtrl globally which means in the form declaration itself, you can access the buffer in any if the form methods.
Thanks,
Girish S.
Hi Girish,
I want to get the values from another control and not in the lookup method.
so in another control clicked method i want to loop through the multi selected values in another control. How to do that?
Hi IntegrationBeginner,
You need to make use of getSelectedFieldValues method of SysLookupMultiSelectCtrl class to get the selected values line below.
Container con; con = multiSelectCtrl.getSelectedFieldValues();
It will return as container and you can loop through the values.
Thanks,
Girish S.
André Arnaud de Cal...
294,217
Super User 2025 Season 1
Martin Dráb
232,978
Most Valuable Professional
nmaenpaa
101,158
Moderator