Get a specific item by user and itemType

679
5
Jump to solution
02-08-2023 01:33 PM
JamesCrandall
MVP Frequent Contributor

I have a Notebook running in AGOL org account that is supposed to find a specific item for a user but it always returns all a list of the items of that type for the user, not the 1 item specified in they query.

 

 

 

items_existing = gis.content.search(query="title:SomeItemTitle, owner:someusername", item_type='PDF')

 

 

 

This does not return the single expected item with the title "SomeItemTitle" and returns the list of all items of type PDF for that user.

 

Am I not implementing this correctly?

 

Edit: the problem is that I NEED to delete an item with the exact title name because it will be recreated again with the same title (getting a new itemId).  What I am running into is that it cannot find the specific item by title and for some reason when it recreates the pdf item it adds on a datetime stamp into the title name.

0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

I just tried to replicate what is found in ESRI docs for the combined query parameters.  The itemType param is outside of the first combo params for title and user, I didn't see anything for using AND condition anywhere.

 

I'm not totally certain that this was even a problem for my implementation at all: I was attempting to run a report off a Survey123 (which works great) but before execution the requirement was to delete any exisitng report previously created.  This was failing and causing a new report to be created with the same title but a datetime stamp was being added to the title.

 

To remedy I simply created another Notebook to cycle through the folder and delete any items of type pdf to guarantee none would exist the next time the generate report Notebook ran.

View solution in original post

5 Replies
JamesCrandall
MVP Frequent Contributor

I think what I'm running into is that if the item title is not found then it will return a list of all items of that type for that user. 

 

This is sort of confusing as I am expecting an empty list!

0 Kudos
Kepa
by Esri Contributor
Esri Contributor

Hello @JamesCrandall,

I see that you use comma to separate the query. Did you try a space or AND clause?

 

JamesCrandall
MVP Frequent Contributor

I just tried to replicate what is found in ESRI docs for the combined query parameters.  The itemType param is outside of the first combo params for title and user, I didn't see anything for using AND condition anywhere.

 

I'm not totally certain that this was even a problem for my implementation at all: I was attempting to run a report off a Survey123 (which works great) but before execution the requirement was to delete any exisitng report previously created.  This was failing and causing a new report to be created with the same title but a datetime stamp was being added to the title.

 

To remedy I simply created another Notebook to cycle through the folder and delete any items of type pdf to guarantee none would exist the next time the generate report Notebook ran.

Kepa
by Esri Contributor
Esri Contributor

Glad you've managed a workaround for it. Just to add up, here you can find query string recommendations and examples on search method in case you want to have a look.

JamesCrandall
MVP Frequent Contributor

Thank you!  This is very useful!

0 Kudos