最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

X ++:如何从Query对象获取QueryRange / How to get QueryRange from Query object X++

网络文摘 William 1380浏览 0评论
Hi Folks, This post is about how to get QueryRange from a query object in x++ code. This is very useful when you have to pass a query on another object and perform a certain operation based on this query and its ranges. To understand this code sample better, let's take a scenario. On FormA I have to build a query (OR use AOT query) on run time based on certain ranges. When the user clicks on a button system will pass this query to FormB and on FormB we have to use this query and its ranges to perform other sets of operations. Now let's see the code, which may need to write on Form B to take a query as a parameter and fetch the ranges and its values in code. Query                                        query = New Query(); QueryBuildDataSource             qbds1; QbueryBuildRange                   qbr1; query              = queryStr(<AOT Query Name OR query object that you passed from Form A>) ; qbds1             = query .dataSourceNo(1); //Dont use dataSourceName(<DS name>) it will give you run time error. Double check the data source sequence on your query. qbr1               = qbds1.range(1); //If there are more than one ranges on DS use 1, 2, 3, and so on. info(strFmt('Range field is %1: Range values is%2:', qbr1.fieldName(), qbr1.value())); Now let's assume there are more than one data source on the query and each data source may have more than one ranges or ranges are unknown. In such case, you can use a for loop to get all data sources on query and ranges. Query                                        query = New Query(); QueryBuildDataSource             qbds; QbueryBuildRange                   qbr; int                                              totalDS, totalRanges; query              = queryStr(<AOT Query Name OR query object that you passed from Form A>) ; totalDS           = query.dataSourceCount(); for(int ds =1; ds<= totalDS; ds++) { qbds = = query.dataSourceNo(ds); totalRanges = qbds.rangeCount(); for(int r =1; r<= totalRanges; r++) { qbr =  qbds.range(r); info(strFmt('Range field is %1: Range values is%2:', qbr.fieldName(), qbr.value())); } } I hope this will help. -Cheers!!! Harry PS: My VM is down for some reason and I couldn't prove the code and have to write it manually so you might get some syntax issues in the above code.
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址