Skip to main content

Notifications

Microsoft Dynamics AX (Archived)
Answered

MultiSelectLookup in AX7

(0) ShareShare
ReportReport
Posted on by 300

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

  • Sankar.R Profile Picture
    Sankar.R 116 on at
    RE: MultiSelectLookup in AX7

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

  • Dalima Chetri Profile Picture
    Dalima Chetri 10 on at
    RE: MultiSelectLookup in AX7

    Hello, 

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

  • Wekey Profile Picture
    Wekey 300 on at
    RE: MultiSelectLookup in AX7

    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
    Sukrut Parab 71,673 Moderator on at
    RE: MultiSelectLookup in AX7

    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
    André Arnaud de Cal... 291,965 Super User 2025 Season 1 on at
    RE: MultiSelectLookup in AX7

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

  • Wekey Profile Picture
    Wekey 300 on at
    RE: MultiSelectLookup in AX7

    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
    André Arnaud de Cal... 291,965 Super User 2025 Season 1 on at
    RE: MultiSelectLookup in AX7

    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
    Wekey 300 on at
    RE: MultiSelectLookup in AX7

    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
    André Arnaud de Cal... 291,965 Super User 2025 Season 1 on at
    RE: MultiSelectLookup in AX7

    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
    Wekey 300 on at
    RE: MultiSelectLookup in AX7

    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

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans