cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ChadVKealey
Level 8

Create SharePoint list item and start Flow

We often develop solutions where a workflow process starts when an item is created in a SharePoint list. The way that Flow works, if we use the "SharePoint > Item is created" trigger, the process always runs as the author of the Flow. In some cases, this works fine, but in others, it creates other issues. For example, if an Approval is involved, the "requestor" for the Approval is the workflow author, not the person who created the item.

 

We've been able to work around this limitation by using PowerApps to call a Flow that creates the item in the list and then starts the Approval. In this context, the Flow executes as the user who created the item via the PowerApp. However, the way we're doing this is a bit complicated and I suspect there is a more efficient way.

 

Basically, this is what we've been doing:

  1. We have the form and a "save" or "submit" button that calls the Flow
  2. In the Flow, for the fields/columns we want to populate from the form, we use the "Ask in PowerApps" bit
  3. This means that the Flow.Run() command needs an argument for each and every field in the form (which may be anywhere from 3 or 4 up to 20 or so)

Step 3 there is where I think there's room for improvement. For example, could we instead use a "Submit" or "Patch" action in PowerApps to create the item, then string on the Flow call, like this:

 

Submit(Form1,SomeList);Flow.Run(ItemID)

 

What I can't figure out, though, is how to get the ID of the item created by the Submit action.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Create SharePoint list item and start Flow

If here you are using the Form control, then you could get the Id created for the new item with:

EditForm1.LastSubmit.ID

If here you are using the Patch() function, then the way to get the ID is a little different.

The whole formula should be:

ClearCollect(LastRecord, 
Patch(DataSource,
defaults(DataSource),
{RecordElements}));
If(!IsEmpty(LastRecord),
Flow.run(First(LastRecord).ID);Navigate(Screen1,fade), Navigate(Screen1, fade))

As the Patch() function returns the created or modified record, we need to collect that data, and then use it with the Flow.run() function.

Function reference:

Patch function in PowerApps

EditForm and Display form controls in PowerApps

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Community Support Team
Community Support Team

Re: Create SharePoint list item and start Flow

If here you are using the Form control, then you could get the Id created for the new item with:

EditForm1.LastSubmit.ID

If here you are using the Patch() function, then the way to get the ID is a little different.

The whole formula should be:

ClearCollect(LastRecord, 
Patch(DataSource,
defaults(DataSource),
{RecordElements}));
If(!IsEmpty(LastRecord),
Flow.run(First(LastRecord).ID);Navigate(Screen1,fade), Navigate(Screen1, fade))

As the Patch() function returns the created or modified record, we need to collect that data, and then use it with the Flow.run() function.

Function reference:

Patch function in PowerApps

EditForm and Display form controls in PowerApps

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ChadVKealey
Level 8

Re: Create SharePoint list item and start Flow

Thanks @v-micsh-msft. So, if I'm dealing with a lot of fields to submit, I'm either spelling them all out in a Patch statement or passing them as parameters/arguments to the Flow.Run() statement. That is, I can't take the easy way out and use a "Submit" action. 

 

Given the choice, I think the Patch approach is at least easier to follow & troubleshoot than the Flow.Run approach. I have another pending project with a list containing almost 30 columns, so that's going to be a fun one Smiley Frustrated

Community Support Team
Community Support Team

Re: Create SharePoint list item and start Flow

Good to know.

 

Please feel free to post back if you need any further help with your PowerApps Projects.

Besides, if you have no more concerns under this topic, please consider accept the post which helps as the solution to close this thread, 

 

 

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ChadVKealey
Level 8

Re: Create SharePoint list item and start Flow

Actually, one further question on the "LastSubmit" part. I'm thinking of a case where you've got multiple people using the app and "Submitting" at the same time. So, persons A, B  and C are all in there and click the "Save/Submit" button, which runs the Patch command, then initiates the Flow on the "LastSubmit". Is it possible that they could get "mixed up" and person A would be initiating the Flow on person B's item? We've done a lot of SPD workflows in the past where we had to add in extra steps or checks to account for this kind of race condition. If the Patch action returns the ID of the item created (as I suspect it does), then this shouldn't be an issue, but I wanted to be sure.