I have this form:
which registration : for customer account
Group : for customer group
all : all cutomer:
then I add button in Cutomer : Sales and marketing>Customers>All customers
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 :
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
}
}
}
}
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.
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??
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.
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)))))
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)))))
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)))))
Ah, sorry. I trust you that you can change the name to the right one.
But I don't have CustTable as dataSource in this form
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(); } }
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156