Hi dear community !
I have a custom request form that has a workflow that will send an approval email containing the web link to the request form with the record context of the request.
The web link simply directs the user to request form with displaying the record that was requested.
In form data source executeQuery() method, I have a condition to check if the current user is not related to the request, then I want to alter the query by removing the record context (RecId) from the query run range and then add a new range with current user Personnel Number instead. just to prevent other users trying to access the request by having the same link shared to them.
What is strange to me is that the executeQuery() method is called twice when accessing the form through web link with record context.
What I understood from tracing the code is as follows:
1st call is when the form has been initiated (no record context yet, so current user personnel number range will be applied).
2nd call is from the FormRunRecordContext.apply() method which will apply the recId range of the request.
Only by the 2nd call, the record context (RecId) will be applied as a range to the QueryRun data source.
The issue is, since the 1st executeQuery() call does not have record context, the current user personnel number range will be added since there is no record context yet. And on the 2nd call, the record context will be available, and it will be added to the query run through standard code. So now I have 2 ranges which contradicts each other and the form will load a blank request.
I tried using the following methods inside
executeQuery():
this.queryRunQueryBuildDataSource().clearRanges();
this.queryBuildDataSource().clearRanges();
And then try to apply the correct ranges, but still getting the blank request because the personnel number range is still applied since the 1st executeQuery() call, even though the Query and QueryRun local objects have been altered in 2nd call in the debugger which shows correct SQL syntax.
What am I missing in order to control the form query if it was accessed with record context or accessed without record context?
Sorry if I'm not clear enough.
Any advice is appreciated !
Thanks in advance !