0

Based on the workflow expression created below, how can I can add/integrate it with update item in a SharePoint website?

Purpose: I would like to tell the SharePoint website that whenever a new row (every time add new item is clicked in edit grid view) is added, auto generate the next column (Reference Number (datatype numeric) value based on the previous value which for example is 10321.

reference_number column in descending order:

enter image description here

For example, let's say the last reference_number value is 10132 then, whenever the user clicks on add new item SharePoint should autogenerate the next reference_number which in this case would be 10133. Thus, each time add new item is clicked, the reference_number will be autogenerated by adding 1 to previous/last value.

How can I setup update item?

Error:

Unable to process template language expressions in action 'Initialize_variable' inputs at line '0' and column '0': 'The template language function 'add' expects its first parameter to be an integer, a float or a decimal number. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#add for usage details.'.

Expression:

add(triggerOutputs()?['body/reference_number'], 1)

Current workflow:

enter image description here

Updated workflow:

enter image description here

4
  • 1
    Are you getting any error while using this expression? Or are you unable to add the expression? Commented Sep 30, 2022 at 17:39
  • Yes let me edit my question to add more details.
    – Ed_Gravy
    Commented Sep 30, 2022 at 17:40
  • 1
    I think you are passing Null value to add function. Are you entering any value in "Reference Number" while saving list form OR you are trying to read the column value from last submitted item and then updated currently added list item? Commented Sep 30, 2022 at 18:11
  • @GaneshSanap, read the column value from last submitted item and then updated currently added list item. So let's say the last reference_number value is 10132 then, when the user clicks on add new item SharePoint should autogenerate the next reference_number which in this would be 10133. So each time ` add new item` is clicked, the reference_number will be autogenerated by adding 1 to previous/last value.
    – Ed_Gravy
    Commented Sep 30, 2022 at 18:25

1 Answer 1

1

Use power automate flow like below to get the last highest value in reference_number column and then update newly created item:

enter image description here

Use correct "internal name" of your reference number column in "Order By". You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

In "Initialize Variable" action, use expression like:

add(outputs('Get_items')?['body/value']?[0]?['reference_number'], 1)

Then use this variable to update the reference number column using "Update item" action.

8
  • Thank you, but I am still getting the same error at the initialize variable step.
    – Ed_Gravy
    Commented Oct 3, 2022 at 13:54
  • 1
    Are there existing list items with value in reference_number column? Can you add screenshot of current flow you are using to original question by editing it and the flow expression you are using? Commented Oct 3, 2022 at 13:59
  • Yes there are, kindly see the updated question
    – Ed_Gravy
    Commented Oct 3, 2022 at 14:04
  • 1
    Did you use the "Get items" action with descending order on column as shown in answer? And used it's output in initialize variable action? Commented Oct 3, 2022 at 14:15
  • 1
    Total how many items are in the list? If you have more than 5000 items, enable pagination from "Get items" action settings. Note: you can get maximum 100000 items using "Get items" action. Commented Oct 3, 2022 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.