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 :
Finance | Project Operations, Human Resources, ...
Answered

How to use QueryBuildRange in adanced query?

(0) ShareShare
ReportReport
Posted on by 932

I have this form: 

pastedimage1676104270024v1.png

which registration : for customer account

       Group : for customer group

all : all cutomer:

then I add button in Cutomer : Sales and marketing>Customers>All customers

pastedimage1676104504749v2.png

I want when I click on setup , I get records from the first form which: 

   the customeraccount = accountNum for the current cutomer

  if the current cutomer have a chainId , search if this group exist in the first Form

 get all the records which the field "Grouping-valid for" = All

so I add eventHandler onclick : 

[FormControlEventHandler(formControlStr(CustTable, CodeBreakButton), FormControlEventType::Clicked)]
    public static void CodeBreakButton_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        Args            args ;
        Object          formRun;
       
        args = new Args();
        args.record(sender.formRun().dataSource("CustTable").cursor());
        args.name(formstr(CodeBreakTable));
        formRun = classfactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.wait();

    }

the I add this code in init method in dataSource  : 

[DataSource]
    class CodeBreakTable
    {
        public void init()
        {
            CustTable   custTable;
            QueryBuildRange qbr1;
            QueryBuildDataSource queryBuildDataSource;

            super();
            if(element.args().record() == custTable)
            {
                Query query = new Query();
                select CompanyChainId from custTable;
                qbr1.value(strFmt('((%1.%2 == "%3" && (%1.%5 == %6)) && ((%1.%2 == "%4") && (%1.%5 == %7)) && (%1.%5 == %8))',
                query.dataSourceTable(tableNum(CodeBreakTable)).name(), // CodeBreakTable %1
                fieldStr(CodeBreakTable, CustomerAccount), // cutomerAccount %2
                fieldStr(custTable, AccountNum),//%3
                fieldStr(custTable, CompanyChainId),//%4
                fieldStr(CodeBreakTable, CodeBreakPattern),//%5
                any2int(CodeBreakPattern::Enregistrement), // %6
                any2int(CodeBreakPattern::Groupe), // %7
                any2int(CodeBreakPattern::Tout)));// %8
            }
        }
    }

But when I run this code : 

I get only the enum registration for the current customer : 

pastedimage1676106661324v3.png

I have the same question (0)
  • BASMA Profile Picture
    932 on at
    thank you very much for all this important information, here is the final result
    I add this code in init method of dataSource and it works :



    [Form]
    public class CodeBreakTable extends FormRun
    {   
        
        [DataSource]
        class CodeBreakTable
        {
            /// 
            ///
            /// 
            public void init()
            {
                CustTable   custTable;
                str   custAccount,chainId;
    
                super();
               custTable = element.args().record() as CustTable;
               if(custTable)
                {
                    custAccount = custTable.AccountNum;
                    chainId = custTable.CompanyChainId;
                    QueryBuildRange queryBuildRange;
                    QueryBuildDataSource queryBuildDataSource;
                    queryBuildDataSource = this.query().dataSourceTable(tableNum(CodeBreakTable));
                    queryBuildDataSource.clearDynalinks();
                    queryBuildDataSource.clearRanges();
                    queryBuildRange = queryBuildDataSource.addRange(fieldNum(CodeBreakTable,DataAreaId));
                    queryBuildRange.value(strFmt('((%1.%2 == "%3")&& (%1.%5 == %6))||((%1.%2 == "%4")&&(%1.%5 == %7))||((%1.%2 == "")&& (%1.%5 == %8)))',
                 queryBuildDataSource.name(), // CodeBreakTable %1
                 fieldStr(CodeBreakTable, CustomerAccount),  // cutomerAccount %2
                 custAccount,//%3
                 chainId,//%4
                 fieldStr(CodeBreakTable, CodeBreakPattern),//%5
                 any2int(CodeBreakPattern::Enregistrement), // %6
                 any2int(CodeBreakPattern::Groupe), // %7
                 any2int(CodeBreakPattern::Tout)));// %8
                } 
            }
        }
    }

  • Martin Dráb Profile Picture
    238,320 Most Valuable Professional on at

    If you just want to skip your code in executeQuery(), use in if block. For example:

    if (custTable)
    {
        ... your modifications of the query ...
    }

    If running the form without a record doesn't make sense at all, you can throw an exception. You should also fix the other form so it doesn't allow opening a related form if it doesn't make sense.

    But that's off topic here - this thread is about "How to use QueryBuildRange in adanced query?". If you have other questions like this, create new threads with appropriate titles and explain your problems in detail there.

  • BASMA Profile Picture
    932 on at

    the problem is when I try to open the parent form, I debug the code and I see that the code of executeQuery of dataSource is executed

    since there is not a selected customer therefore the query is not applicable : 
    there is a condition to add ,
    so that we can apply this query only if I have a calles form??
  • Martin Dráb Profile Picture
    238,320 Most Valuable Professional on at

    That surely isn't related to clearDynalinks.

    Didn't you just showed us a different query? Please give us a more detailed description of your problem.

  • BASMA Profile Picture
    932 on at

    it solves the problem for the called form , but the parent form I can't get all the data because the query ,

    only this condition is applied : 

    ((CodeBreakTable.CustomerAccount == "")
    && (CodeBreakTable.CodeBreakPattern == 3)))))

  • Martin Dráb Profile Picture
    238,320 Most Valuable Professional on at

    You're saying that it didn't solve the problem, but you're showing a query that actually has the problem resolved.

    If you read what you gave us, you'll see that the condition CustTable.AccountNum=CodeBreakTable.CustomerAccount indeed isn't there. Let me re-post your code in a more meaningful way, to make it eaiser for you to read:

    SELECT FIRSTFAST FORUPDATE * FROM CodeBreakTable(CodeBreakTable)
    USING INDEX Idx WHERE
    ((((CodeBreakTable.CustomerAccount == "")
    && (CodeBreakTable.CodeBreakPattern == 1))
    ||((CodeBreakTable.CustomerAccount == "")
    &&(CodeBreakTable.CodeBreakPattern == 2))
    ||((CodeBreakTable.CustomerAccount == "")
    && (CodeBreakTable.CodeBreakPattern == 3)))))

  • BASMA Profile Picture
    932 on at

    I use clearDynalinks(), but it doen't resolve the problem

    the query in form parent is : 

    SELECT FIRSTFAST FORUPDATE * FROM CodeBreakTable(CodeBreakTable) USING INDEX Idx WHERE ((((CodeBreakTable.CustomerAccount == "")&& (CodeBreakTable.CodeBreakPattern == 1))||((CodeBreakTable.CustomerAccount == "")&&(CodeBreakTable.CodeBreakPattern == 2))||((CodeBreakTable.CustomerAccount == "")
    && (CodeBreakTable.CodeBreakPattern == 3)))))

  • Martin Dráb Profile Picture
    238,320 Most Valuable Professional on at

    Ah, sorry. I trust you that you can change the name to the right one.

  • BASMA Profile Picture
    932 on at

    But I don't have CustTable as dataSource in this form

  • Martin Dráb Profile Picture
    238,320 Most Valuable Professional on at

    Calling executeQuery() during initialization is a bad design. Let me suggest clearDynalinks() for the third time:

    public void init()
    {
    	super();
    
    	if (this.args())
    	{
    		custTable = this.args().record() as CustTable;
    		custTable_ds.clearDynalinks();
    	}
    }

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 867 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 348 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans