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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

MultiSelectLookup in AX7

(0) ShareShare
ReportReport
Posted on by 302

Hello,

I am working in AX7.

I have created a multiselect lookup field in my form. Lookup works fine. 

But after selecting the values from the lookup and when i try to access the lookup again for a different row or for the same field, the previously selected values are still selected and it is not getting unselected until i have to unselect manually.

Can anyone suggest me why this is happening.

I have used the following code,

    [FormControlEventHandler(formControlStr(Reasons, AssetTransactionType), FormControlEventType::Lookup)]
    public static void AssetTransactionType_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormRun                         formRun = sender.formRun() as FormRun;
        TransactionType_TMP             transactionType_TMP;
        TransactionType_TMP_Populate    transactionType_TMP_Populate = new TransactionType_TMP_Populate();
        
        transactionType_TMP_Populate.populateTempTable(transactionType_TMP);
        queryRun = new QueryRun(queryStr(TransactionType_TMPQuery));
        queryRun.setCursor(transactionType_TMP);
        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        sysLookupMultiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQueryRun(formRun,sender,queryRun/*,false,[tableNum(TransactionType_TMP),fieldNum(TransactionType_TMP,TransType)]*/);
        ce.CancelSuperCall();

    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormControlEventHandler(formControlStr(Reasons, AssetTransactionType), FormControlEventType::Modified)]
    public static void AssetTransactionType_OnModified(FormControl sender, FormControlEventArgs e)
    {
        FormDataSource      reasonTable_ds = sender.formRun().dataSource("ReasonTable");
        FormDataSource      transactionType_TMP_ds = sender.formRun().dataSource("TransactionType_TMP");
        SysQueryForm        sysQueryForm = new SysQueryForm(queryRun);
        container           reason;
        container           reasonRecId;
        ReasonTable         reasonTable;
        ReasonTable         reasonUpdate;
        DefaultReasonTable  defaultReasonTable;
        int                 value;
        int                 id;

        reasonTable = sender.formRun().dataSource(1).cursor();
        reason = sysLookupMultiSelectCtrl.getSelectedFieldValues();
        reasonRecId = sysLookupMultiSelectCtrl.get();
        
        ttsbegin;

        select forupdate reasonUpdate
            where reasonUpdate.RecId == reasonTable.RecId;
        
        reasonUpdate.TransactionType = con2Str(sysLookupMultiSelectCtrl.getSelectedFieldValues(),';');
        reasonUpdate.update();
        reasonTable_ds.research(true);
        //queryRun.detach();
        //queryRun.saveUserSetup(false);        
        //reasonTable_ds.refresh();
        //transactionType_TMP_ds.research();
        //transactionType_TMP_ds.refresh();

            while select forupdate defaultReasonTable
                where defaultReasonTable.ReasonRecId ==  reasonTable.RecId
            {
                defaultReasonTable.delete();
            }

        defaultReasonTable.clear();
        defaultReasonTable.initValue();

        for(value = 1; value <= conLen(reasonRecId); value++)
        {
            defaultReasonTable.ReasonRecId = reasonTable.RecId;
            for(value = 1; value <= conLen(reason); value++)
            {
                defaultReasonTable.TransactionType = conPeek(reason,value);
                defaultReasonTable.insert();
            }            
        }

        ttscommit;

    }


Thanks

*This post is locked for comments

I have the same question (0)
  • Sankar Ramalingam Profile Picture
    262 on at

    If the event handlers are in the same class then declare it as global static variables.

  • Dalima Chetri Profile Picture
    10 on at

    Hello, 

    How can i use the same variable  sysLookupMultiSelectCtrl , queryRun within different event handlers? Please suggest

  • Wekey Profile Picture
    302 on at

    Thanks.

    I checked with the standard, I have done the same thing what they have done.

    Ans sysLookupMultiSelectCtrl.set(conNull()); worked form me.

    I got the solution and its working fine.

  • Verified answer
    Sukrut Parab Profile Picture
    71,710 Moderator on at

    Try to look at standard example like logisticsPostalAddress form or vendtable form . ALso try to set  

    sysLookupMultiSelectCtrl.set(conNull());

  • André Arnaud de Calavon Profile Picture
    301,908 Super User 2025 Season 2 on at

    Did you already look at examples in the standard as I had suggested in two earlier replies?

  • Wekey Profile Picture
    302 on at

    There is no link between the selection and the main table. I created this table transactionType_TMP to populate the enum values in the table and I have added the table in the query to display it as a lookup.

    I first tried to create it as a temp table but the I didn't get the lookup that's why I changed it into a regular table. I have created a new field in reason table and the selected values are stored in the reasonTable itself. So there is no link with the lookup table and the main table.

  • André Arnaud de Calavon Profile Picture
    301,908 Super User 2025 Season 2 on at

    I do think there is something forgotten on the link between the main table and the selection table. Can you review if the table does have a reference field for what record the selection was saved?

    Also compare the coding and tables used with a standard example (e.g. address books on party)

  • Wekey Profile Picture
    302 on at

    Hello!.

    Sorry for the hurry.

    Yes it allows to store data. Its not a temporary table. Its a regular table.

    Thanks

  • André Arnaud de Calavon Profile Picture
    301,908 Super User 2025 Season 2 on at

    Hi Wekey,

    Note that we are all volunteers on this forum. You cannot expect an answer within one hour. We answer questions in spare time.

    Is your transactionType_TMP table a temporary table or does it allows for saving data? Have you compared your code with a standard example to see if there are any differences?

  • Wekey Profile Picture
    302 on at

    hello,

    Any suggestions?

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

News and Announcements

Season of Giving Solutions is Here!

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
TAHER Mehdi Profile Picture

TAHER Mehdi 3

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
Volodya Profile Picture

Volodya 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans