The CreatorCon Call for Content is officially open! Get started here.

Incrementing and decrementing by 1

Jacob23
Mega Guru

Hi,

 

I am trying to increment an integer field on the sc_req_item table. The idea is in a flow a 'For each' loop will call a sub-flow which has an update record action. The update record will +1 to the integer field, then at the very end of the sub-flow it will -1 from the field. 

The reason for this is because we want users to be able to submit a request where they can select either 1-11 items. each of these items create a task. We also want all tasks to be created at the same time so we have un-checked the 'wait for completeion' on the sub-flow that runs inside the 'For each'. The main flow will then look at this integer field and will know to complete out the requested item once the interger field hits 0 (the original value).

 

To update the field I am using the script function in the flow action.

var count = fd_data.subflow_inputs.requested_item.u_parallel_process_count;


count++;


return count;

 

The issue I am getting is the field when being triggered by its related catalog item will only go up by 1.

After doing some quick testing I found that when I run the 'Test' function in flow designer this successfully inrements and decrements. For some reason when it is triggered via the catalog item it only updates to 1 no higher.

 

Am I missing something in the code I am using. I am about to start using gs.warn and check the logs to see what I am getting after I declare the variable, and after teh return count++.

 

TO NOTE: the -1 in the subflow does not run intil the task is closed, so this is not the case of the system immediately +1 and then -1.

1 ACCEPTED SOLUTION

Just did a quick test with wait for duration. Looks like doing a small wait for condition right after the sub-flow action got it working. Odd that there is some difference in speed for it to work on the Test function but fails for catalog item trigger.

 

Thanks for taking the time to look!

View solution in original post

7 REPLIES 7

RaghavSh
Kilo Patron

try below:

 

return parseInt(count)+1;


Raghav
MVP 2023
LinkedIn

The field nows says 2. I selected 3 items extepcting the for each to run 3 times - meaning the integer field should display with the value of 3. However, all of the actions say it went to 2.0, see image below:

Jacob23_2-1670935985133.png

 

For loop usually starts from 0, i am not sure about flow designer but you can try below in various scenarios if thay works in all cases:

 

return parseInt(count)+2;


Raghav
MVP 2023
LinkedIn

I have not made the changes you suggested but something to note. I did some logging so my code looks like this now (I also reverted back to previous for logging):

var count = fd_data.subflow_inputs.requested_item.u_parallel_process_count;
gs.warn('WUBBA:'+ count);
count++;
gs.warn('WUBBA:'+ count);

return count;

 

I am getting the variable after it is declared and then getting it after it has been ++. You can see in the logs that this get the field value and sees it as 0 each time the action runs. You can also see it is adding 1, but since it resets on each record in the for each loop it doesnt go above 1. What could this suggest?

Jacob23_0-1670941783999.png

 

NOTE: I did not add any logging for when I tried with parseInt.