web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to add a multi-select dropdown for Language in a form extension

(0) ShareShare
ReportReport
Posted on by 50

I have been scratching my head on this one for a few days now, for what seemed like a simple requirement. Basically I need to be able add a Language field to an existing form through an extension that allows users to select multiple languages. The languages should be listed with their LanguageId and Description in the dropdown, and the user should be able to select as many as they need.

I followed examples from the two following sites and was able to come very close to being able to complete this:

Adding multi-select lookup field in System parameters form using form extension

HOW TO CREATE A MULTI-SELECT LOOKUP AND SAVE VALUES IN TABLE

There are a couple of issues with the solutions from those sites. The first issue is that you need to use a QueryBuildDataSource in order to populate the Language dropdown and the language description is surfaced through a data method rather than a field, and I have not been able to find any possible way to include the Description as the QBDS needs to use actual fields on the table. The second issue is that it appears that the RecId needs to be included in the query (which causes it to display in the dropdown as well). If the RecId is not included, the dropdown still actually works and will save the correct values to the form, but whenever you try to change the values in the dropdown at a later date it does not remember your selections and has the first item in the list selected by default.

In order for me to be able to get the above working as intended I would both need a way to include the Description in the dropdown, and also hide the RecId from being visible in the dropdown. I have included a sample of the code I have used so far if that is of any help.

    [FormDataSourceEventHandler(formDataSourceStr(EcoResProductParameters, EcoResProductParameters), FormDataSourceEventType::QueryExecuted)]
	public static void EcoResProductParameters_OnQueryExecuted(FormDataSource sender, FormDataSourceEventArgs e)
	{
        Object mySender = sender.formRun();
        mySender.setLanguageLookupValues();
	}

    public void init()
    {
        next init();
        this.initLanguageMultiSelectLookup();
    }

    private void initLanguageMultiSelectLookup()
    {
        Query languageQuery = new Query();

        QueryBuildDataSource languageDataSource = languageQuery.addDataSource(tableNum(LanguageTable));
        languageDataSource.addSelectionField(fieldNum(LanguageTable, LanguageId));
        languageDataSource.addSelectionField(fieldNum(LanguageTable, RecId));
        languageDataSource.addOrderByField(fieldNum(LanguageTable, LanguageId));

        languageLookupControl = SysLookupMultiSelectCtrl::constructWithQuery(
            this,
            EcoResProductParameters_SPCLanguages,
            languageQuery,
            true);
    }

    public void setLanguageLookupValues()
    {
        container ids;
        container recIds;
        int i;

        FormDataSource ecoresproductparameters_ds = this.dataSource(formDataSourceStr(EcoResProductParameters, EcoResProductParameters)) as FormDataSource;
        EcoResProductParameters ecoResProductParameters = ecoresproductparameters_ds.cursor();

        for(i=1; i<=conLen(str2con(ecoResProductParameters.SPCLanguages,";")); i  )
        {
            recIds  = LanguageTable::Find(conPeek(str2con(ecoResProductParameters.SPCLanguages,";"),i)).RecId;
            ids  = conPeek(str2con(ecoResProductParameters.SPCLanguages,";"),i);
        }

        languageLookupControl.set([recIds,ids]);
        ids = conNull();
        recIds = conNull();
    }

    [FormControlEventHandler(formControlStr(EcoResProductParameters, EcoResProductParameters_SPCLanguages), FormControlEventType::Modified)]
    public static void EcoResProductParameters_SPCLanguages_OnModified(FormControl sender, FormControlEventArgs e)
    {
        FormDataSource ecoresproductparameters_ds = sender.FormRun().dataSource(formDataSourceStr(EcoResProductParameters, EcoResProductParameters)) as FormDataSource;

        EcoResProductParameters ecoResProductParameters = ecoresproductparameters_ds.cursor();

        FormStringControl languagesControl = sender as FormStringControl;

        ttsbegin;
        ecoResProductParameters.selectForUpdate(true);
        ecoResProductParameters.SPCLanguages = languagesControl.text();
        ecoResProductParameters.update();
        ttscommit;
    }

Failing being able to get it working as described above, it has also been suggested that I could create a Form Lookup to accomplish the same but I am not familiar with that so if you would be able to provide some guidance it would be appreciated. My Google skills have been failing me on trying to find any example solutions.

I have the same question (0)
  • huijij Profile Picture
    19,811 on at

    Hi ChosenSilver,

    Do you have any errors with your current code?

  • ChosenSilver Profile Picture
    50 on at

    There are no errors in the code, it just is not able to do what I need it to.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans