Updating a single field in a SharePoint List using Power Automate Flows
Updating a single field in a SharePoint List using Power Automate Flows
Updating a single field in a SharePoint List using Microsoft
Flows (aka Microsoft Power Automate) can be a bit tricky with longer lists with
lots of required fields and drop downs possibly resetting your data. The work
around is code, but if there are non-developers creating flows, then this
process is even more cumbersome. As a result, the Flow below will do the heavy
lifting using a separate list and then anyone can populate that list from a
different Flow when such a thing is needed.
First step: create the list
Here’s the input needed in this list.
List: The name of the list
SiteLink: The link to the site (trim off /lists/xyzlist)
IDFromSource: This is the internal ID of the item to update
FieldToUpdate: The name of the field you want to update. This is case
sensitive.
ValueForField: What you want to set it to.
Next, create the Flow. Here’s what it will look like
When a SharePoint item is created or modified (the “or
modified” will make it easier to correct errors along the way): Here you’ll
point to the list that was created above.
Initialize Variable: If the List name contains spaces or
underscores you will need to replace them. For the value, set it to an
expression. Here’s the expression from the screenshot:
replace(replace(triggerOutputs()?['body/Title'], '_', '_x005f_'),
' ', '_x0020_')
This requires nesting two replace statements to first
replace _ with _x005f_ and second to replace a space with _x0020_. The order is important
as underscores are added so those must be replaced first. The
triggerOutputs()?['body/Title'is from the dynamic content tab and that’s
the code generated when the field is selected.
Next, URL Encode spaces out of the List name (yes, both are
needed) with this expression which replaces spaces with %20
replace(triggerOutputs()?['body/Title'],' ', '%20')
The final Variable to initialize is the internal field name and
that uses a double replace again
replace(triggerOutputs()?['body/FieldToUpdate'],' ', '_x0020_')
Now that all the variables are set, add a step to Send an
HTTP request to SharePoint

The SiteLink comes directly from the list, and then the URI
field is the API call to get the specific item. At runtime it will generate
something like
_api/web/lists/GetByTitle('My%20List')/items(101)
Headers:
Content-Type |
application/json;
odata=verbose |
IF-Match |
* |
X-HTTP-Method |
MERGE |
Accept |
application/json;
odata=verbose |
{'__metadata':{'type':'SP.Data.<InternalListName>ListItem'},'<internalFieldName>':'<ValueForField>'}
Or written another way to be more readable:
{
'__metadata':
{
'type':'SP.Data.<InternalListName>ListItem'
},
'<internalFieldName>':'<ValueForField>'
}
Lastly, delete the item from the list that triggered the
workflow. This way the trigger list should always be empty and anything that
remains in the list has not executed and can be reviewed and retried.
Feel free to comment below with any questions. :-)
Comments
Post a Comment