cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tania986
New Member

How to sum +1 to an existing sharepoint list field

Hello, 

This is what i am trying to do: Running every day a flow that adds +1 to a field depending on the status. So if the status= in Progress then the flow will update the field belonging to 'Days in Progress' adding 1 to the current value. And same process for the others statuses. 

This is what i did (after multiple tries and attemps):

- Recurrence (every day at night)

- Get items

- Switch (depending on each status) If status == 'In Progress' then :

- Update item and in the Days in Progress field I added the following expression : 

add(1,outputs('Get_items')?['body/value']?['Days_in_Progress'])
 
This gives me an error: InvalidTemplate. Unable to process template language expressions in action 'Update_item' inputs at line '1' and column '14397': 'The template language expression 'add(1,outputs('Get_items')?['body/value']?['Days_in_Progress'])' cannot be evaluated because property 'Days_in_Progress' cannot be selected. Array elements can only be selected using an integer index. 
 
Could you please helppppppp ? thanks a lot !! 

 

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

@tania986 

Please consider using coalesce() WDL function for such manipulation

add(1,coalesce(item()?['Days_in_Progress'],0))

Not with my laptop, unable to test



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Excellent !! that works !! thank you very much!! i didnt know the trick to control the nulls !! really good to know that.

And this is the final solution (i think i could improve it and make it smaller, but it works for now):

tania986_0-1638285584876.png

And inside of 'Apply to each': 

tania986_1-1638285768149.png

 

In the expression I have something like this:

add(1,coalesce(outputs('Get_item')?['body/Days_x0020_in_x0020_Progress'],0))

 

This is adding +1 to the current value and also controlling the nulls in case the field in sharepoint is empty !! 

View solution in original post

7 REPLIES 7
efialttes
Super User
Super User

Hi!
I believe you need an 'Apply to each' action block to iterate through all your SP List elements.

- Recurrence (every day at night)

- Get items
-Apply to each, assigning as its inputthe following expression (same result if  you select 'value' output from 'Get items' action block from dynamic content menu):

outputs('Get_items')?['body/value']



Now, inside your Apply to each you should place your 'Switch' action block, also 'Update item'
Finally, the expression you should use for adding 1 to your target column, since you are inside an 'Apply to each', is:

add(1,item()?['Days_in_Progress'])

Hope this helps
 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hello efialttes ! thanks for your reply. I actually missed on my explanation that i was getting the value from get items and inside apply each i had the switch. I just change the expression as you commented before but i am still getting and error: InvalidTemplate. Unable to process template language expressions in action 'Update_item' inputs at line '1' and column '14397': 'The template language function 'add' expects its second parameter to be an integer or a decimal number. The provided value is of type 'Null'

tania986_0-1638213392326.png

where in apply each i have the follwing :

tania986_1-1638213603972.png

and in Days in Progress (expression):  add(1,item()?['Days_in_Progress'])

 

And this gives me this error : error: InvalidTemplate. Unable to process template language expressions in action 'Update_item' inputs at line '1' and column '14397': 'The template language function 'add' expects its second parameter to be an integer or a decimal number. The provided value is of type 'Null'

Hi!

So first issue solved, right?

What you are describing is a totally different issue. From the new error description, it seems your column is not mandatory, and some of the items in the list have no value assigned to it (null value)

Would you consider forcing this column as mandatory on your list, or do you need your flow to translate the null value into a zero?

Thanx!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hello ! thanks for your response and sorry for my late reply .. yes, I think i should convert null value into zero, this would be the best approach. Thank you !!

@tania986 

Please consider using coalesce() WDL function for such manipulation

add(1,coalesce(item()?['Days_in_Progress'],0))

Not with my laptop, unable to test



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Excellent !! that works !! thank you very much!! i didnt know the trick to control the nulls !! really good to know that.

And this is the final solution (i think i could improve it and make it smaller, but it works for now):

tania986_0-1638285584876.png

And inside of 'Apply to each': 

tania986_1-1638285768149.png

 

In the expression I have something like this:

add(1,coalesce(outputs('Get_item')?['body/Days_x0020_in_x0020_Progress'],0))

 

This is adding +1 to the current value and also controlling the nulls in case the field in sharepoint is empty !! 

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (1,600)