cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carudev
Helper II
Helper II

How to compare an ID from excel file with an entire sharepoint list?

Hello guys!

 

I have a list on Sharepoint where I need to update it with a new list.

It basically works like this: I take the ID that I have in excel from a new list and compare it with the ID that is already there in the Sharepoint.
Example:

If  IDExcel = IDSharepoint, update item. And so far it works very well!

 

But there is the case that: If there is no IDExcel within the Sharepoint list, create a new item. And this case is not working. Look at how I'm trying to do:

 

EXAMPLE=   

IDExcel = "123456", and I want to know if this IDExcel exists within the Sharepoint list.

 

carudev_1-1617819843134.png

 

carudev_0-1617819576472.png

 

  • Translate images: "Não contem" is like "Doesn't contain", and "Saidas" is like "Outputs". 

 

Value is the output of "Get Items", and I want to check if there is an ID inside the Value.

It doesn't have to be done exactly that way, but that's what I've managed to think so far.

 

Look at the IDLinha field inside the Value, this is what I need to use to compare::::::

carudev_2-1617819952567.png

 


So what I need is: check if an ID exists within my Sharepoint list and if it does not exist, create an item. But this comparison is not working, any ideas?

 

THANK YOU!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

Your approach will not work because you are comparing the "Value" element from the get items action which is an array of objects. What you need is an array of IDs from SharePoint which will make your comparison work. You can do it with a select action like this:

2021-04-08_07-04-47.gif

This will produce you a clean array of IDs, which will look something like this:

[
  1,
  2,
  3
]

You can then easily do your comparison:

2021-04-08_07-09-50.png

Does that make sense?

View solution in original post

20 REPLIES 20
NorthernChuck
Helper III
Helper III

What does "Nao Contem" (forgive the lack of accents) mean? Does Not Contain? 
Can you hover over the Data Operation "Saidas" and paste what the function is? (or type it out) 
I ran into a similar situation where FOO contained data but the function kept evaluating as NULL. 
The dynamic value had something like triggerbody()?['body']?['next']?['what_I_Wanted']  My fix was to manually type in the function and trim body so it was triggerbody()?['next']?['what_I_Wanted']

I get the feeling from your screenshots you are experiencing something similar......

"Não contem" is like "Doesn't contain", and "Saidas" is like "Outputs". 

And this "Saidas" / "Outputs" is my ID that I extracted from excel. I want to update the list on Sharepoint with an excel. 

Then I compare the excel ID with that of the Sharepoint. This happens daily, whenever this excel comes to me by email I take it and use it to update the list on Sharepoint.

Currently, my suspicion is inside the Saidas.
If you do a test run, and then show the raw outputs of when that Saidas is first generated? Can you also show the output of the evaluation step? 
I'm convinced it's something in either 
1. the first time you engaged this Data Operation (Saidas)
OR
2. It's in the evaluation itself (if you can hover over that Saidas and type out or screengrab how it formatted itself) 

illmatic
Helper IV
Helper IV

@carudev    hi, i think you may need to change your condition.   it sounds like you need to check if your 'IDExcel' is empty, yes?  If so, I believe you can just select the 'IDExcel' field and check if it is equal to "null".

 

ETA:  instead of 'value,'  you can either do a Parse JSON action ahead and directly select the IDLinha field by copying and pasting the output of your Get Items action into the sample JSON of the parse JSON action.  Or you can write an expression:  body('get_items')?['IDLinha']

vikulkar
Community Support
Community Support

Hi @carudev ,

 

Please try the condition: 

length(outputs('Get_items')?['body/value']) and compare it with 0

Carudev.PNG

 

If it is 0 then a new item can be created.

 

Thanks and Regards,

  Vikas K

@carudev The length approach might actually be easier. If it comes back 0 then it's pretty much the same result as "not contain". 

NorthernChuck_0-1617824990400.png

In your original condition, this is what I'm after (should you chose to pursue a text comparison). 
May the Force be With You @carudev and Good Luck 🙂

carudev
Helper II
Helper II

Guys, actually I need to compare it like this:


The Excel ID I already have its value.

 

For example:

 

IDExcel = "1234567"

 

Then I want to know if the IDSharepoint, which is inside the Value of GetItems, is the same as the IDExcel.

 

This is my IDExcel:

 

carudev_0-1617825295733.png

 

And I want to compare it with this sharepoint list:

 

carudev_1-1617825343778.png

 

So if there is no IDLinha = IDExcel in my Sharepoint list, then I create the item. Because I'm checking if the item already exists in the sharepoint or not.

No, I want to know if the IDExcel exists within the Sharepoint list, if it does not exist, create a new item. So I need to compare the IDs.

carudev_2-1617825638207.png

 

This is my Saidas, it is the excel id that I want to compare. 

vikulkar
Community Support
Community Support

@carudev ,

are you not leveraging the FilterQuery in your GetItems action?

vikulkar_0-1617825913980.png

it should be something like:

 

IDSharepoint eq '10336821'

@carudev I'm following your logic. I trust that the data is there (or in this case not there). What I'm trying to help with is the evaluation. I'd really like to see the actual output of your evaluation of Value Nao Contem Saidas   I'm convinced it's something there. 

If not, can you provide some sample data with 1 or 2 rows (records)? This way I can test as well. I once had a select that needed me to manually write out item() function with the array index number of 0. I find when things like evaluations don't work it's because of the expression....... 

NorthernChuck_0-1617826099481.png

 

carudev
Helper II
Helper II

My flow works like this:

Every day I receive an email with an excel file, so I get this excel and "ForEach" line inside it I compare it with the lines there in the Sharepoint list, if the file ID is the same as the ID in the Sharepoint list, I update it the item. And it works well, as I compare item by item using the ForEach ID on Sharepoint. 

 

So now I need to deal with cases where the item in the file does not exist in the sharepoint. So I take the IDExcel that came in the file and check if that ID already exists or not in Sharepoint, because if it does not exist I will create it there in the Sharepoint list.

 

Below more details of my flow:

 

I use Get Items, then I use a For Each to work with the lines in the file, split them up and do a series of treatments on the lines:

carudev_0-1617826703881.png

 

And then I compare the line ID of the file with all the lines in the Sharepoint:

 

carudev_1-1617826911398.png

 

Value comes from Get Items, and this is its content of Value:

 

carudev_2-1617827058795.png

 

And the "Saidas" is this: that is the ID that I already have - it was extracted from the excel file - and I want to know if it already exists or not in Sharepoint.

 

carudev_3-1617827165540.png

 

 

Thank you guys! Sorry for the terrible English, but I think now I have better explained my problem. Thank you!

No worries @carudev !! 🙂 We will get to the bottom of this elusive evaluation. 
Unfortunately I am out for the day, but I will review your post either later this evening or tomorrow morning!

Cheers, 
~C

So, the easiest way for me to help you is to try and recreate myself. I'll gladly help, but your sample data is in a picture format and it's rather large. Can you paste me in text that sample payload (replace things like Display Name: Kermit Frog, Email: kermit@frog.com - I just need sample data to reproduce) 

#2 @vikulkar is very correct in their suggestion. Filtering using an Odata query would accomplish what you are looking for. If you had to, you could load the file more than once and then have more than one singular Odata filter to match up with your "series of treatments"

Shelly-S
Frequent Visitor

I am having the exact same issue myself ... trying to compare an ID column in a SharePoint list to the ID column in a .csv file. If the Excel ID exists in the SPO list, update that list item with the data in the .csv file. Otherwise, create a new SPO list item and populate with .csv data. 

 

I was following along with a YouTube tutorial (Power Automate - Bulk Add Excel data to SharePoint list), but the OData filter query isn't working for me. I was using:  LMSEnrollmentID eq 'ID' in the SharePoint Get Items action, where LMSEnrollmentID is a column in the SPO list and ID is a column in the .csv file. I'll be following this thread to see how it works out! 

 

 

 

 

Paulie78
Super User III
Super User III

Your approach will not work because you are comparing the "Value" element from the get items action which is an array of objects. What you need is an array of IDs from SharePoint which will make your comparison work. You can do it with a select action like this:

2021-04-08_07-04-47.gif

This will produce you a clean array of IDs, which will look something like this:

[
  1,
  2,
  3
]

You can then easily do your comparison:

2021-04-08_07-09-50.png

Does that make sense?

View solution in original post

NorthernChuck
Helper III
Helper III

That makes sense to me. It would explain why the comparison wasn't working. Of all the small itches I have with PowerAutomate, I miss having a shell that provides feedback the most! Kudos on the excellent reply with a gif animation!

OMG!!!!!! IT WORKED!!! THANK YOU SO MUCH @Paulie78 . OMG!!

I WAS ALREADY LOST WITHOUT KNOWING HOW TO MAKE THIS WORK, THANK YOU SO MUCH!!!!!

Paulie78
Super User III
Super User III

WOOHOO OMG! NO PROBLEM AT ALL, MY PLEASURE! 😂🤣

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

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

Users online (94,196)