How to do it...

To create a query function, follow these steps:

  1. Create a new class in the project and name it ConQueryRangeFunctions.
  2. To add a query function to the class, in this case, to get the current worker record ID, write the following lines of code:
[QueryRangeFunction] 
public static str CurrentWorkerNum()
{
RefRecId currentWorkerRecId =
HcmWorkerLookup::currentWorker();
HcmWorker worker;

if(currentWorkerRecId == 0)
{
// if we return and empty string, it will match all
// records. So return a string that will both cause
// the no records to be found in the query range,
// but also to give the user a clue as to what
// happened. You should create this as a label,
// without spaces, us the following as an example.
return '#NotFound#';
}
select PersonnelNumber
from worker
where worker.RecId == currentWorkerRecId;

return worker.PersonnelNumber;
}
You may notice that it tries to add Attribute to the end, if you use intelli-type, and that some of the methods in SysQueryRangeUtil also end in Attribute. This is the old convention and is no longer required.
  1. The second part of the trick is how to use it. Build the project and open https://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=USMF&mi=HcmWorkerListPage in your browser.
  2. Select the OPTIONS action pane tab, as shown in the following screenshot:
  1. Click on Advanced Filter/Sort and add a range for Personnel number, as shown in the following screenshot:
  1. Type the following line of code into the Criteria column and press OK:
(ConQueryRangeFunctions::CurrentWorkerNum()) 
  1. You should see, when using the Contoso demo data in the USMF company, that only the user Julia Funderburk is shown.
  2. If you click on the heading for Personnel number, our query function code is also listed as a matches criterion. As these functions are usually used when submitting routines or printing reports, the advanced filter dialog is more commonly used.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.103.227