This is an alternative solution to the post ‘Determine unique name for file to save to SharePoint folder with just 3 flow actions‘ with just 2 flow actions to determine the unique name for a file to save to a SharePoint folder.
The ‘Configure run after’ of the first action after the Do until action should include ‘has failed’ to let the flow run continue.
With the result() function it’s possible to get the results from the Do until action and extract the unique file name.
The
Reference guide to using functions in expressions for Azure Logic Apps and Power Automateresult()
function accepts a single parameter, which is the scope’s name, and returns an array that contains information from the first-level actions in the specified scoped action, such as aFor_each
,Until
, orScope
action.
The result array from the ‘Do until NotFound’ action looks like this:
[
{
"name": "Get_file_metadata_using_path",
"inputs": {
"host": {
"apiId": "subscriptions/744cf0e1-fb2c-4a5c-9fbf-ff414e1b901b/providers/Microsoft.Web/locations/westeurope/runtimes/europe-002/apis/sharepointonline",
"connectionReferenceName": "shared_sharepointonline",
"operationId": "GetFileMetadataByPath"
},
"parameters": {
"dataset": "https://company.sharepoint.com/sites/site",
"path": "/library/folder/This is a unique file name (3).pdf"
}
},
"outputs": {
"statusCode": 404,
"headers": {
"Vary": "Origin",
"X-SharePointHealthScore": "1",
"X-MS-SPConnector": "1",
"X-SP-SERVERSTATE": "ReadOnly=0",
"DATASERVICEVERSION": "3.0",
"SPClientServiceRequestDuration": "17",
"SPRequestGuid": "7708f829-2131-44df-9bc9-dca433a37927",
"request-id": "7708f829-2131-44df-9bc9-dca433a37927",
"MS-CV": "KfgIdzEh30SbydykM6N5Jw.0",
"Strict-Transport-Security": "max-age=31536000",
"X-FRAME-OPTIONS": "SAMEORIGIN",
"Content-Security-Policy": "frame-ancestors 'self' teams.microsoft.com *.teams.microsoft.com *.skype.com *.teams.microsoft.us local.teams.office.com *.powerapps.com *.yammer.com *.officeapps.live.com *.office.com *.stream.azure-test.net *.microsoftstream.com *.dynamics.com;",
"MicrosoftSharePointTeamServices": "16.0.0.22001",
"X-Content-Type-Options": "nosniff",
"X-MS-InvokeApp": "1; RequireReadOnly",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "false",
"Cache-Control": "max-age=0, private",
"Date": "Wed, 29 Dec 2021 18:15:20 GMT",
"P3P": "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"",
"X-AspNet-Version": "4.0.30319",
"X-Powered-By": "ASP.NET",
"Content-Length": "168",
"Content-Type": "application/json",
"Expires": "Tue, 14 Dec 2021 18:15:20 GMT",
"Last-Modified": "Wed, 29 Dec 2021 18:15:20 GMT"
},
"body": {
"status": 404,
"message": "File not found\r\nclientRequestId: 7708f829-2131-44df-9bc9-dca433a37927\r\nserviceRequestId: 7708f829-2131-44df-9bc9-dca433a37927"
}
},
"startTime": "2021-12-29T18:15:20.0806547Z",
"endTime": "2021-12-29T18:15:21.2681584Z",
"trackingId": "0612f770-3498-43f5-97a1-a52f3fd02e6a",
"clientTrackingId": "08585608051656145914637424442CU129",
"clientKeywords": [
"testFlow"
],
"code": "NotFound",
"status": "Failed",
"repetitionCount": 4
}
]
We can use the following expression to get the unique file name from the path value:
last(split(first(result('Do_until_NotFound'))?['inputs']?['parameters']?['path'],'/'))
The test flow run shows the unique file name in the supporting Compose action after the Do until action.
Now the unique file name can be used in the subsequent action to save the file to the SharePoint folder.