web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / When file is created i...
Power Automate
Unanswered

When file is created in SharePoint, copy file to an existing directory up one level. Adapatable. Dynamic. Child Flow.

(0) ShareShare
ReportReport
Posted on by 152

This I can do, for a single 'fork' in a flow where the 'create path' is clearly set in the 'picker' provided in the Power Automate card UI.

BUT...

What I need is an adaptable step (which will become a 'child flow') to be inserted at any point in a multi-forked flow and take dynamic data from the previous 'create file' step, say it's:

"/Shared Documents/Garry/Bob/Steve/Transmittals/my-file-name.txt"

and make a copy to:

"/Shared Documents/Garry/Bob/Steve/Queries/my-file-name.txt".

 

Most important is that I can do this in an adaptable manner because the flow where this is required has too many parallel paths to be adding a second 'create file' step under the first on each one and using the 'picker' to re-locate the new directory. This would take days and if the directory name changed, days more.

 

What I have currently available is all the data from the previous 'create file' step including item ID, size, ID, Name, DisplayName, Path, LastModified, ETag, FileLocator, isFolder plus all the variables which comprise the name and extension of the file to be saved.

Could Path be applicable here? And if so is it relative or absolute and can I parse path to 'step it up' one level. The destination folder names will be the same in all cases, but the paths to get there are always unique.

 

Like this:

Screen Shot 2021-03-25 at 11.25.22 am.png

 

Any help greatly appreciated!

 

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @HydrogenUtility 

     

    Is this what you require?

     

    DamoBird365_0-1616666646299.png

    I used substring on the last index of /, this would be based on the dynamic value path (assuming it doesn't include the file name).  Otherwise I am sure you can apply the same to your available strings.

     

    substring(outputs('Compose'),0,lastIndexOf(outputs('Compose'),'/'))

     

    Good luck.

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here

  • HydrogenUtility Profile Picture
    152 on at

    Thanks @DamoBird365 , I conceived of the same myself, and indeed, it does modify the string per my requirements. The persistent issue remains (stepping back from the problem), finding the correct objects to perform the sub-string methods on.

    Path appears to contain data from the 'site' downward and can be used for part of the copy file description. Which elements are carried through from 'create file' to point to Site?

     

    Screen Shot 2021-03-26 at 7.54.48 am.png

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @HydrogenUtility 

     

    What trigger are you using?

     

    You can get @{triggerOutputs()?['body/{Link}']} from when a file is created (properties only)

     

    Same with the Get File (properties only) action.

     

    I'm sure you've got this handled as it will warn you but if you are triggering when a file is created and then you later create a file in the same doc lib, you could end up in a mean loop.

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here

     

  • HydrogenUtility Profile Picture
    152 on at

    Thanks @DamoBird365 . The trigger for the flow happens no fewer than 25 steps upstream and prior to this action, as a fork among dozens of forks so think it's not relevant here.

    The 'create file' action does offer the following as parameters, however:

    "parameters": {
                "dataset": "https://mydomain.sharepoint.com/sites/MyProjects",
                "folderPath": "/Shared Documents/principal_project/directory_1/directory_2/directory_3/Transmittals/}"
      Where, somewhat elusively, the site appears to be referred to as "dataset".

    I see this commonly enough in my own dev work where the name given in development perseveres through to production where it's relevance is lost from a nomenclature point of view.

    I'll attempt to use "dataset" as an ersatz "site" reference and report back.

    Thanks again for input!

     

     

  • HydrogenUtility Profile Picture
    152 on at

    UPDATE: I have managed to successfully alter the copy to destination path 'up one' level using replace() expression, in conjunction with some string manipulation.

    What I'm not succeeding in doing is gaining access to any 'site' parameter from the earlier create file step (as above: "parameters": { "dataset": "https://mydomain.sharepoint.com/sites/MyProjects",). What is the correct syntax for accessing "dataset" as an item in "parameters" and reusing in an expression?

     

    This doesn't work for accessing site:

     

     

    outputs(‘the_earlier_create_file_step’)?[‘parameters']?['dataset']

     

     

    Although the syntax passes in the expression editor once reaching the step where the copy file ought to happen this comes through as 'null'.

     

    JSON from the previous step:

     

     

    {
     "inputs": {
     "host": {
     "connectionName": "shared_sharepointonline_1",
     "operationId": "CreateFile",
     "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
     },
     "parameters": {
     "dataset": "https://myDomain.sharepoint.com/sites/MyProjects",
     "folderPath": "/Shared Documents/folder_1/folder_2/folder_3/folder_4/folder_5/folder_6/folder_7/folder_8/folder_9/@{variables('projectPhase')}_@{variables('Keyword')}_@{variables('modFileKeyFull')}_@{variables('timeStamp')}",
     "name": "@{variables('projectPhase')}_@{variables('Keyword')}_@{variables('modFileKeyFull')}_@{variables('timeStamp')}.eml",
     "body": "@outputs('export_the_.eml_for_filing')?['body']"
     },
     "authentication": "@parameters('$authentication')"
     },
     "runtimeConfiguration": {
     "contentTransfer": {
     "transferMode": "Chunked"
     }
     }
    }

     

     

    operative part:

     

     "parameters": {
     "dataset": "https://myDomain.sharepoint.com/sites/MyProjects",

     

     

    and the error:

    "

    The 'inputs.parameters' of workflow operation 'Copy_file' of type 'OpenApiConnection' is not valid. Error details: The resolved string values for the following parameters are invalid, they may not be null or empty: 'dataset'

    "

     

    H2U

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @HydrogenUtility 

     

    The correct path includes inputs - see my screenshot from a parser:

    DamoBird365_0-1616999301396.png

    This works fine for me:

     

    DamoBird365_1-1616999315998.png

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here

  • HydrogenUtility Profile Picture
    152 on at

    Thanks @DamoBird365 , the omission of ['index']? is a significant omission. But I'm still getting 'null'.

    Let me see if I can provide more detail:

     

    This is a simplification of the scenario where the error persists:

     

    Screen Shot 2021-03-29 at 8.27.57 pm.png

    Screen Shot 2021-03-29 at 8.28.09 pm.png

    Screen Shot 2021-03-29 at 8.27.31 pm.png

    Here you can see that the Current Site Address in the copy file card as well as the Destination Site Address have been filled with:

    body('Parse_JSON')?['inputs']?['parameters']?['dataset']

    which, in turn gets populated with:

    outputs('Create_File')

    which seems to be the only way to do this. But there is the 'null' in the inputs and the error states:

     

    The 'inputs.parameters' of workflow operation 'Copy_file' of type 'OpenApiConnection' is not valid. Error details: The resolved string values for the following parameters are invalid, they may not be null or empty: 'dataset'

     

    Where to from here?

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @HydrogenUtility 

     

    Can you share the history of the input to the parse Json action?  You are trying to capture the dataset?

    DamoBird365_0-1617011546846.png

    If it is returning null, it's either empty or your expression is invalid.

     

    If you copy and paste the output to this call, we can use a JSON parser to evaluate 

    body('Parse_JSON')?['inputs']?['parameters']?['dataset']

    as you are indicating it is empty?  

     

    Given that you have parsed the data in the parse json action, I would have thought that it would allow you to select it dynamically. 

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here

     

  • HydrogenUtility Profile Picture
    152 on at

    Thanks for swift attention @DamoBird365 .

    The output from one of the create file actions (one per attached file from the trigger).

    {
     "statusCode": 200,
     "headers": {
     "Transfer-Encoding": "chunked",
     "Vary": "Origin,Accept-Encoding",
     "X-SharePointHealthScore": "2",
     "X-MS-SPConnector": "1",
     "X-SP-SERVERSTATE": "ReadOnly=0",
     "DATASERVICEVERSION": "3.0",
     "SPClientServiceRequestDuration": "457",
     "SPRequestGuid": "b89321df-4f68-490d-9057-c8969b4b1b1d",
     "request-id": "b89321df-4f68-490d-9057-c8969b4b1b1d",
     "MS-CV": "3yGTuGhPDUmQV8iWm0sbHQ.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;",
     "MicrosoftSharePointTeamServices": "16.0.0.21117",
     "X-Content-Type-Options": "nosniff",
     "X-MS-InvokeApp": "1; RequireReadOnly",
     "Timing-Allow-Origin": "*",
     "x-ms-apihub-cached-response": "true",
     "Cache-Control": "max-age=0, private",
     "Date": "Mon, 29 Mar 2021 09:36:21 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-Type": "application/json; charset=utf-8",
     "Expires": "Sun, 14 Mar 2021 10:36:21 GMT",
     "Last-Modified": "Mon, 29 Mar 2021 09:36:21 GMT",
     "Content-Length": "660"
     },
     "body": {
     "ItemId": 2867,
     "Id": "%252fShared%2bDocuments%252fOPS-o006%2b-%2bIT%2band%2bDigital%252fsandbox%252f2Test_Document2.pdf",
     "Name": "2Test_Document2.pdf",
     "DisplayName": "2Test_Document2.pdf",
     "Path": "/Shared Documents/OPS-o006 - IT and Digital/sandbox/2Test_Document2.pdf",
     "LastModified": "2021-03-29T09:36:22Z",
     "Size": 363840,
     "MediaType": "application/pdf",
     "IsFolder": false,
     "ETag": "\"{CBD0E8CD-FE4D-49FF-89D7-888A857E65E5},2\"",
     "FileLocator": "dataset=aHR0cHM6Ly9oeWRyb2dlbnV0aWxpdHkuc2hhcmVwb2ludC5jb20vc2l0ZXMvSDJVT3BlcmF0aW9ucw==,id=JTI1MmZTaGFyZWQlMmJEb2N1bWVudHMlMjUyZk9QUy1vMDA2JTJiLSUyYklUJTJiYW5kJTJiRGlnaXRhbCUyNTJmc2FuZGJveCUyNTJmMlRlc3RfRG9jdW1lbnQyLnBkZg=="
     }
    }

     

    and the input into the same:

    	
    host	
    apiId	"subscriptions/9f3a0e5f-8…1/apis/sharepointonline"
    connectionReferenceName	"shared_sharepointonline"
    operationId	"CreateFile"
    parameters	
    dataset	"https://myDomain.sharepoint.com/sites/The_Site_I_Want_to_Pass"
    folderPath	"/Shared Documents/OPS-o0… IT and Digital/sandbox"
    name	"2Test_Document2.pdf"
    body	"JVBERi0xLjUNJeLjz9MNCjEg…mVmDTI3MjA4OQ0lJUVPRg0="

     ...where my target dataset "https://myDomain.sharepoint.com/sites/The_Site_I_Want_to_Pass" exists.

     

    And yes the

    body('Parse_JSON')?['inputs']?['parameters']?['dataset']

    was added dynamically and this is indeed what it was generated (when hovering on the element in the GUI).

    The output to that call is:

    {
     "statusCode": 200,
     "headers": {
     "Transfer-Encoding": "chunked",
     "Vary": "Origin,Accept-Encoding",
     "X-SharePointHealthScore": "2",
     "X-MS-SPConnector": "1",
     "X-SP-SERVERSTATE": "ReadOnly=0",
     "DATASERVICEVERSION": "3.0",
     "SPClientServiceRequestDuration": "457",
     "SPRequestGuid": "b89321df-4f68-490d-9057-c8969b4b1b1d",
     "request-id": "b89321df-4f68-490d-9057-c8969b4b1b1d",
     "MS-CV": "3yGTuGhPDUmQV8iWm0sbHQ.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;",
     "MicrosoftSharePointTeamServices": "16.0.0.21117",
     "X-Content-Type-Options": "nosniff",
     "X-MS-InvokeApp": "1; RequireReadOnly",
     "Timing-Allow-Origin": "*",
     "x-ms-apihub-cached-response": "true",
     "Cache-Control": "max-age=0, private",
     "Date": "Mon, 29 Mar 2021 09:36:21 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-Type": "application/json; charset=utf-8",
     "Expires": "Sun, 14 Mar 2021 10:36:21 GMT",
     "Last-Modified": "Mon, 29 Mar 2021 09:36:21 GMT",
     "Content-Length": "660"
     },
     "body": {
     "ItemId": 2867,
     "Id": "%252fShared%2bDocuments%252fOPS-o006%2b-%2bIT%2band%2bDigital%252fsandbox%252f2Test_Document2.pdf",
     "Name": "2Test_Document2.pdf",
     "DisplayName": "2Test_Document2.pdf",
     "Path": "/Shared Documents/OPS-o006 - IT and Digital/sandbox/2Test_Document2.pdf",
     "LastModified": "2021-03-29T09:36:22Z",
     "Size": 363840,
     "MediaType": "application/pdf",
     "IsFolder": false,
     "ETag": "\"{CBD0E8CD-FE4D-49FF-89D7-888A857E65E5},2\"",
     "FileLocator": "dataset=aHR0cHM6Ly9oeWRyb2dlbnV0aWxpdHkuc2hhcmVwb2ludC5jb20vc2l0ZXMvSDJVT3BlcmF0aW9ucw==,id=JTI1MmZTaGFyZWQlMmJEb2N1bWVudHMlMjUyZk9QUy1vMDA2JTJiLSUyYklUJTJiYW5kJTJiRGlnaXRhbCUyNTJmc2FuZGJveCUyNTJmMlRlc3RfRG9jdW1lbnQyLnBkZg=="
     }
    }

    One thing I do note is that the outputs (operative part from "body": downward) are the same, and it only place that dataset "https://myDomain.sharepoint.com/sites/The_Site_I_Want_to_Pass" exists is in the input of the create file action...

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @HydrogenUtility 

     

    I'm going cross eyed on this one - i.e. it's a hard one to follow but I think I now know what is happening.

     

    The value you are looking for is not in the body of the output of the create file action - it's an input which you have specified manually.  If you specifically want the site URL as a dynamic value you will have to use an additional action Get File Properties which will return the link of the file inclusive of the URL.  You can then use a substring on the indexof the Document Library Name.

     

    DamoBird365_0-1617015673112.png

     

    Have we got there?  Or do I need to hand this one over to others to look at?

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Cheers,
    Damien


    P.S. take a look at my new blog here

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard