cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

SQL to Share Point Insert Update

Hi Guys,

 

Hoping some one here can help me as I've spent alot of time in trying to get this to work correctly and are now at wits end. Basically its a push of data from a master SQL Server table set of values ( thats gets periodically updated )  to a Sharepoint List that will be used later one by a different department.

 

Walking through my logic:

Get all the rows from SQL server 

In a loop

    Get the sharepoint item by providing an OData filter that uses a column name against a column provided in the  SQL server list. ( works like a charm )

    Check condition checks to see if the body returned for sharepoint list is empty

    Condition Code:     not(empty(body('Get_items')?['value'])) 

    (seems to work as it will flip between conditions depending on wheteher there are rows in Sharepoint with searched value)

    If found,

        Update the Sharepoint list from the SQL values, ( data rows get updated correctly)

         otherwise Insert the new values from the SQL values (problem)

End of Loop

 

I've been able to assemble this so far and know I am close , but have a problem when creating the Sharepoint items.

It seems to take forever and I believe that it is trying to insert all rows from SQL everytime around the loop.

I know that the Apply to Each 2 input should be a single  item but cannot reference a single row value ( where the arrow is ) that Im suppose to already have.

 

Is there another step I have to add before hand ?

 

Completely puzzled..

 

Much thanks for any input and I've done a large search in the community looking for something similiar

 

Cheers

 

 

image.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Support
Community Support

Re: SQL to Share Point Insert Update

Hi @majero ,

 

What you mean is to update the item if there is already an expected item in the list? And if not, create a new item?

 

You could refer to the following method to configure Flow, Apply to each 2 is not required, directly configure Create item action in If no branch.

Since the create item action is already in the loop of Apply to each-Value, you could directly reference Dynamic content from Get rows action.

In addition you could try to use length() function to determine if the item exists.

Image reference:

1.PNG

 

Best Regards,

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

View solution in original post

Highlighted
New Member

Re: SQL to Share Point Insert Update

OK,

I've updated the Flow and it now working correctly.

the extra 'For Each' in the Yes/No were automatically added when created the condition, not sure why. Deleting and re-adding the Xreate Sharepoint item (without the foreach) solved the problem.

 

Final solution for future reference for anyone following in the footsteps.

Again much thanks.

 

 

Flow_image_3.jpg

 

 

 

 

 

 

 

 

View solution in original post

6 REPLIES 6
Highlighted
Community Support
Community Support

Re: SQL to Share Point Insert Update

Hi @majero ,

 

What you mean is to update the item if there is already an expected item in the list? And if not, create a new item?

 

You could refer to the following method to configure Flow, Apply to each 2 is not required, directly configure Create item action in If no branch.

Since the create item action is already in the loop of Apply to each-Value, you could directly reference Dynamic content from Get rows action.

In addition you could try to use length() function to determine if the item exists.

Image reference:

1.PNG

 

Best Regards,

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

View solution in original post

Highlighted
New Member

Re: SQL to Share Point Insert Update

HI Barry,

 

much thanks for the reply , really appreciated

 

In answers to your question,

Yes, if the Item already exists in Sharepoint it must be updated regardless, otherwise it should be inserted into the Sharepoint List as a new item from the master SQL server list of data.

 

I've removed the extra Apply to Each and the Length function works beautifully in the condition, however, when running with rows already in the sharepoint list, I get a failure on the Apply to each 2 (Sharepoint insert) as it tries to re-insert all the rows every time it loops not just the one new one that should be inserted.

 

I believe this is because in the 'Apply to Each 2' the selected output has been  set to 'Value List of items'.  Thats the only option you have to get your hands on the SQL Server values for each time around the loop.

 

Ive tried to change that output to Current Value but that fails with an expression array issue  error 

'ExpressionEvaluationFailed. The execution template action 'Apply_to_each_2' failed. the result of the evaluation of the 'Foreach; expression "@items(Apply_to_each')  os of type Object, the result must be a valid array.

 

Im so close..

 

 

 

 

Highlighted
Community Support
Community Support

Re: SQL to Share Point Insert Update

Hi @majero ,

 

Could you provide screen shoot of current Flow configuration?

 

It seems that you should fill value from Get items action in Apply to each 2 instead of Current item.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
New Member

Re: SQL to Share Point Insert Update

 

Sorry Picture wqorth a thousand words!!

Current gives array error, values[] provides the entire list  each time around the loop

 

Much thx for your help

 

 

Flow_image 1.jpgFlow_image_2.jpg

Highlighted
Community Support
Community Support

Re: SQL to Share Point Insert Update

Hi @majero ,

 

You don't need to add Apply to each in If no and configure create item action directly.

 

You could configure Flow according the screen shoot provided by me in last post.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
New Member

Re: SQL to Share Point Insert Update

OK,

I've updated the Flow and it now working correctly.

the extra 'For Each' in the Yes/No were automatically added when created the condition, not sure why. Deleting and re-adding the Xreate Sharepoint item (without the foreach) solved the problem.

 

Final solution for future reference for anyone following in the footsteps.

Again much thanks.

 

 

Flow_image_3.jpg

 

 

 

 

 

 

 

 

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (6,653)