GetFirstValueForQuery works different in background actions
Hi
I experience a weird behavior when using GetFirstValueForQuery in a background action.
I got a main list where i run a scheduled background action. In this action i get values of items in a different configuration list by their list number (a number column).
The values returned are always the value of the very first item in the configuration list regardless of the number requested in the query.
The query used is:
<Where><Eq><FieldRef Name="EHConfigImplemTaskNumber"></FieldRef><Value Type="Number">"[[@Variables.CurrentTaskID]]"</Value></Eq></Where>
which correctly results in :
<Where><Eq><FieldRef Name="EHConfigImplemTaskNumber"></FieldRef><Value Type="Number">414</Value></Eq></Where>
Where the number 414 in this example is one of 20 consecutive list item Numbers vom 401 to 421.
As mentioned before, the returned Title field (for example) from these items is always the title of the very first entry in the list.
Now the weird thing, for debug purposes, i have created the same action on a form action button.
From there it works as expected! I get the correct values of queried items.
Do i miss something simple here?!
Thanks a lot for any help in this case
Best wishes
Dieter
-
Hi DieterJauslin,
I guess the parameter in your caml query should be a number and not a string. Therefore you have to get rid of the quote characters before and after the variable CurrentTaskID
<Where><Eq><FieldRef Name="EHConfigImplemTaskNumber"></FieldRef><Value Type="Number">[[@Variables.CurrentTaskID]]</Value></Eq></Where>
or how about using the current item value directly instead of using a variable?
<Where><Eq><FieldRef Name="EHConfigImplemTaskNumber"></FieldRef><Value Type="Number">[[=[[@Action.Loop_thru_all_tasks.CurrentItem]].EHImplemTasnNumber]]"</Value></Eq></Where>
BR Matthias
0 -
Hi Matthias
You are absolutely right. I tried so much on friday evening that i simply pasted the wrong query. Sorry ;)
However, i just back on track and tried to cleanup everything. I have set an email with the responses ...
In the Body i have put this code ...var content = [[@Web.GetFirstValueForQuery('Configuration Implementation Tasks', '<Where><Eq><FieldRef Name="EHConfigImplemTaskNumber"></FieldRef><Value Type="Number">[[=[[@Actions.Loop_thru_all_tasks.CurrentItem]].EHImplemTaskNumber]]</Value></Eq></Where>', 'Title')]];content = content + "<br>" + "Current Task Number : " + [[=[[@Actions.Loop_thru_all_tasks.CurrentItem]].EHImplemTaskNumber]];return content;I wanted to make sure that i use the correct lookup values when actually doing the lookup.
The response i got looks like this:Workstep update Product Status ListCurrent Task Number : 414I expect the first line to be the title of the item referenced by the current task number (2nd line for debugging).
Now i got an email for each of the existing task items. Each has its own number (401 to 421) which is being looked up in the configuration list.
But still, i only get back the Title value of "Workstep update Product Status List" which is the very first item in the configuration.
What makes me laugh is, when i use the same code on form action button, it works as expected!
I just got this problem when using it on the backend actionBest wishes and thanks a lotDieter0 -
Hi Dieter
I can reproduce your issue and have a random guess that it's caching the result of the query function to reduce duplicate time consuming calls during execution - for sure this works not as expected when the query contains dynamic changing variables inside a loop which returns different item(s) as result...
Did create a support ticket on your behalf that we fix this issue in an upcoming product development sprint.
If you have any more question in this topic we can continue communication in the ticket.
Thank you for the feedback!0
Please sign in to leave a comment.
Comments
3 comments