cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AimenBoulahia
Frequent Visitor

Duplicate an existing flow inside another Automated flow

Hello guys,

This post will be a little bit long, I hope you would be patient with me and excuse my poor English 

I have a SharePoint List (let's call it ListA), I create an associated flow that do some notification actions, all of this is working very well. 

Now I won't have just one list, in the future i will have "n similar lists" which they will need the same flow, I couldn't find a way to create one flow that handle everything for these all lists, so i realised I can quite simply duplicate that flow (Save as copy) then edit the list name in the flow trigger, right ?

 

since the SharePoint site will be used by a simple users (which they don't have access to Power Automate and duplicate the flow), I need to do it automatically when a new list is created !

 

so what i have done until now:

  • I get the first flow
  • I get the flow definition (which it's in JSON format), connectionReferences, status ...etc
  • I create another flow with another name, I'll use the same connectionReferences, status, while i should edit some properties in the flow definition
  • the properties i am talking about is the List ID, which it should be changed for every duplicated flow, right ?

     

Now the problem that i have encountered until now:

 

  1. How can i manage that flow definition, edit the property "path" (from the json format: "triggers→when_an_item_is_created→inputs→path") ?

Note that the value of "path" is: "/datasets/@{encodeURIComponent(encodeURIComponent('.../sites/Support'))}/tables/@{encodeURIComponent(encodeURIComponent('3939098e-a076-48e8-b020-b0df1589b327'))}/onupdateditems"

 

While I should change that ID ''3939098e-a076-48e8-b020-b0df1589b327" by another one I just got and save it in a variable

 

So I searched for a way to edit this JSON, and I found an expression named "setProperty(<object>, '<property>', <value>)" and in order to edit that "path" property, I need to use nested setProperty (please refer to this link to understand what i'm saying)

 

here is what I build:

setProperty(body('Get_Flow')['properties']['definition'],'triggers', setProperty(body('Get_Flow')['properties']['definition']['triggers'], 'When_an_item_is_created_or_modified',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified'], 'inputs',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified']['inputs'], 'path','/datasets/@{encodeURIComponent(encodeURIComponent(''.../sites/Support''))}/tables/@{encodeURIComponent(encodeURIComponent(''def533d7-8ede-4f29-b882-57d48a90c2d8''))}/onupdateditems' ))))

 

as you can see at the end of this expression, I used the two quotes ('') to use the quote inside that expression (for example, inside a concatenation expression

  • concat('client's ','request') this is false 
  • concat('client''s ','request') this is true, and the output will be (client's request)

 

So, the previous expression setProperty i mentionned above, it works fine and the new flow in created perfectly with the new name of the new list (let's call it ListB), but my desire is to replace the new ID dynamically and not like i've done so far, it should like this:

 

setProperty(body('Get_Flow')['properties']['definition'],'triggers', setProperty(body('Get_Flow')['properties']['definition']['triggers'], 'When_an_item_is_created_or_modified',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified'], 'inputs',setProperty(body('Get_Flow')['properties']['definition']['triggers']['When_an_item_is_created_or_modified']['inputs'], 'path','/datasets/@{encodeURIComponent(encodeURIComponent(''.../sites/Support''))}/tables/@{encodeURIComponent(encodeURIComponent(''def533d7-8ede-4f29-b882-57d48a90c2d8''))}/onupdateditems' ))))

 

and this will replace put the text exactly as it is "variables('ID')",  while it should replace the value of this variable !

 

Thank you.

 

 

 

 

 

 

1 REPLY 1
Gristy
Resident Rockstar
Resident Rockstar

check out wonder laura's blog for some tips on this it is what got me to a working solution, but you are right it is not pretty.

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (61,575)