I have a table of tasks with a Priority column and I need to make sure the Priority of all tasks are sequential. I’m not planning to do this with validation, but rather when the form is submitted, the server action will update the other records as needed.
So if the user edits or enters a new task, and assigs it a Priority that already exists, when it’s saved, the server action needs to bump the Priority value all other records with a value equal to or greater than the one being saved.
The query checks if there are other records with a Priority greater or equal to the one being saved:
Then, if there are any, the repeat loops over them and increments the values. The problem I’m having is the SetValue is concatenating the value instead of adding it. So 6 becomes 61 instead of 7 like it should.
I’ve used the Data Formats screen to configure the value:
I think 1 and 2 are already taken care of. As I mentioned, #3 is concatenating the value + 1 instead of adding it. So if the current priority is 6, it sets it to 61 instead of 7.
Well if it’s concatenating rather then adding +1 - you really missing correct data type in DB.
Just checked my solution - all worked as expected - on each update it’s adds +1 to previous value.
I think it really comes down to the question of how to get the Set Value to add one to itself as in:
{{PriorityValue + 1}}
instead of:
{{PriorityValue}}1
which it insists on doing when I save.
How does it show if you click to update using the data pickers (rather than the text editor)? I have a similar step in a while loop:
If I view it using the lightning icon it looks fine,
in the text editor it displays incorrectly and keeps reverting as you describe, though this looks to be a display issue only.
The actual json shows correctly. It may be if you update using the lightning icon you’ll end up with the correct output (though there still looks to be a bug in how it displays in the text editor!).
Everything works as expected (with the JSON correction) down through the first loop in the repeat. The query finds the correct records and the Priority value is incremented and the first record is updated with the incremented value. But then it stops. It seems the Condition (selected in the image) is not being met after that. The output from Developer tools shows this:
As you can see, the first one is true and the rest are false. The first record was updated from 7 to 8, so PriorityValue now holds the value of 8 and the second record has a Priority of 8 so the Condition should be true for index 1. So, why is it failing??
This could be down to how you've named the set value step. Again I think mine was a similar use case/ issue and took a while to work through (with some valued help from @mebeingken ).
Try adding a global name of PriorityValue to both the Set Value steps, and then change the name of the steps to PriorityValueInitial and PriorityValueUpdated (or similar).
This has to do with the scope of access of the variable in each step, by making it global it can be accessed within the repeat too (or something along those lines!). By just using the name field it may be only the initial PriorityValue is accessible (I'm sure there a technically better explanation than that but hopefully you get the general idea).
You are correct, @sbecks! I added a global name of PriorityValue to both of the Set Value steps, and bingo, it works! I had seen something about scopes in another thread, but thought it must not apply to this case, because of the fact it was working the first loop through. Would be really nice to have some good documentation for how this is to work.
I didn’t quite follow you on changing the name of the steps, but this seems to have taken care of the problem. Thanks so much for your time!