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, ...
Answered

Checkbox not working with x++ code

(0) ShareShare
ReportReport
Posted on by 1,836

I have created check box named " show line with scan serial id " in the item arrival forms " line's "  overview header section , i my execute query i have written code so if i click my check box the item with  serial no  scan should appar in grid if i untik check box the grid should be as it is, my code is given below can any one help me out what is wrong with my code.

public void executeQuery()
{
    QueryBuildDataSource   Qbds;

    Qbds = this.query().dataSourceTable(tableNum(WMSJournalTrans));
    Qbds.clearRanges();

    Qbds.addRange(fieldNum(WMSJournalTrans, InventSerialId)).value(queryValue("Scan"));

    super();

}
 

7750.Checkbox.PNG

I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi Dineshkarlekar,

    Where you have added the range if the check box is unchecked.

    Also in the form you have only serial number with value "Scan". Try to create one more line with serial number other then "scan" and check.

    So if you uncheck it nothing happens as you don't have serial number other then "Scan".

    public void executeQuery()
    {
        QueryBuildDataSource   Qbds;
    
        Qbds = this.query().dataSourceTable(tableNum(WMSJournalTrans));
        Qbds.clearRanges();
        if(checkbox.selection() == NoYes::yes)
        {
            Qbds.addRange(fieldNum(WMSJournalTrans, InventSerialId)).value(queryValue("Scan"));
        }
        else
        {
            qbds.clearRanges();
        }
    
        super();
    
    }

    Thanks,

    Girish S.

  • Suggested answer
    Komi Siabi Profile Picture
    13,109 Most Valuable Professional on at

    Hello,

    You would have to call the execute query of your datasource when your combox is modified.

    Take a look at this.

    community.dynamics.com/.../form-filter-based-on-combo-box-selection-in-ax

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

    Hi Dinesh,

    As you shared a screenshot of AX2012, I have moved your question to the Dynamics AX forum.

    You can add the mofified() method to the check box and call the executeQuery() method. In this executeQuery() method, you should add or remove the range based on the actual checkbox value.

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi girish , thanks for reply 

    because of this line i am getting only scan serial id i am having rest of serial id created. thanks for the code but i am getting error

     Qbds.addRange(fieldNum(WMSJournalTrans, InventSerialId)).value(queryValue("Scan"));

    pastedimage1664262135378v1.png

    Checkbox2.PNG

  • GirishS Profile Picture
    27,827 Moderator on at

    Try the below code.

    If(checkbox.checked())
    
    {
    
    }
    
    else
    
    {
    
    //
    
    }

    Thanks,

    Girish S.

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    By the way, you could write your code in a simpler way and avoid deleting ranges for fields unrelated to your requirement. For example:

    QueryBuildRange serialIdRange =  SysQuery::findOrCreateRange(this.queryBuildDataSource(), fieldNum(WMSJournalTrans, InventSerialId));
    serialIdRange.value(checkbox.checked() ? queryValue("Scan") : SysQuery::valueUnlimited());

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi martin , thanks for reply , you want me to write this code in my execute query method.

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Yes, I just modified your code. I didn't meant moving it to another method.

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi andre ,thanks for reply 

    i have two methods but i am not getting desired output can you please explain.

    public void executeQuery()
    {
        QueryBuildDataSource   Qbds;
    
        Qbds = this.query().dataSourceTable(tableNum(WMSJournalTrans));
        Qbds.clearRanges();
    
        Qbds.addRange(fieldNum(WMSJournalTrans, InventSerialId)).value(queryValue("Scan"));
       
        
        super();
    
    }
    
    

    public boolean modified()
    {
        boolean ret;
    
        ret = super();
        if(ret)
        {
       wmsJournalTrans_ds.executeQuery();
        }
        return ret;
    }

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi komi , thanks for reply

    i tried your steps but not getting the desired output

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 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans