cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HydrogenUtility
Helper III
Helper III

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

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!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
DamoBird365
Super User
Super User

@HydrogenUtility 

 

The simplest solution to your problem is:

DamoBird365_0-1617017340334.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

View solution in original post

HydrogenUtility
Helper III
Helper III

The simplest things, yes often.

In this case, almost! And thank you @DamoBird365 !

 

Composing the reusable URL further upstream is in fact a small act of genius. And it works for the original Create File. Sadly there's still the requisite folder path item in Copy File which is now refusing to act on the output of Create File. If I manually give the folder path to Copy File it works. So I reckon it's half way there!

Thanks for all the assistance. I've learned a lot already.

I'll persist with this some more and report.

View solution in original post

16 REPLIES 16
DamoBird365
Super User
Super User

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

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

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

 

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
Helper III
Helper III

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

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
Helper III
Helper III

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
Super User
Super User

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

 

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
Super User
Super User

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

 

HydrogenUtility
Helper III
Helper III

This is good. But even so, the Get file properties requires an input Site Address and Library Name, which are added manually in your example, meaning that there's a breakdown on the dynamic URL passing right away. It's cruel but I really need this dynamic from the time the create file step is completed. Otherwise hard-coding the Site Address and Library Name across the multiple branches of the problem flow would be bad. And intolerant to change.

 

You are of course right @DamoBird365  that the site URL is entered manually in the original case (Create File), but surely is is then accessible going forward?

 

Your current solution will solve it if this first step were squared away. It seems so obvious to stare at...

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

 

Thanks again for your persistence!

DamoBird365
Super User
Super User

@HydrogenUtility 

 

The simplest solution to your problem is:

DamoBird365_0-1617017340334.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

View solution in original post

HydrogenUtility
Helper III
Helper III

The simplest things, yes often.

In this case, almost! And thank you @DamoBird365 !

 

Composing the reusable URL further upstream is in fact a small act of genius. And it works for the original Create File. Sadly there's still the requisite folder path item in Copy File which is now refusing to act on the output of Create File. If I manually give the folder path to Copy File it works. So I reckon it's half way there!

Thanks for all the assistance. I've learned a lot already.

I'll persist with this some more and report.

View solution in original post

Hi @HydrogenUtility 

 

Brilliant!

 

I've also tried with a folder path and it works for me.  See below:

 

DamoBird365_0-1617020906573.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
Helper III
Helper III

Yes! Just did the same. So if one is both must be, so to speak.

Thanks.

HydrogenUtility
Helper III
Helper III

Final solution:

Forget copy file as I'm implementing a create file immediately prior. So, instead, I spend resources on parsing the URL and directory structure to perform:

a) create file in folder/folder1/folder2/folder3/transmittal/live-folder-name-based-on-centent/file.pdf

b) create file in folder/folder1/folder2/folder3/review/variable-name/file.pdf

The steps between a&b basically use concat() and replace() to get the folder name hierarchy strings and fiddle them to make them appropriate for 'steering' toward the next write location.

Thanks @DamoBird365 for patient assistance.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (1,755)