Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can i get the variables of an object after search?

Markus W_ BENES
Contributor
August 4, 2023

I hope someone can help me; I have a little bit of a beginner question. How can i access an object and its variables/attributes after a successfull search. In log i get results so its working but iam not able to access or handle the result... I simply like to get the key, name and so on, within the .each but dont know how to do that.

 

def asset = Assets.search('objectType IN ("Users") AND Email = "test@test.at"').each {

      return it.Key // this doesnt work
     //log.debug(it) // log result

}  
     

2 answers

2 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
August 4, 2023

Hi @Markus W_ BENES

I suggest that you use ScriptRunner HAPI feature to simplify this approach. You can refer to the Working with Assets sections to get some ideas.

To use ScriptRunner's HAPI, you will need to upgrade your ScriptRunner plugin to the latest release, i.e. 8.8.1 or at least version 7.11.0.

I hope this helps to solver your question. :-)

Thank you and Kind regards,

Ram

Markus W_ BENES
Contributor
August 4, 2023

Thank you all for your answers; for me this was the solution; i found it on the site linked by @Ram Kumar Aravindakshan _Adaptavist_ 

it.getString("Name")
1 vote
Answer accepted
Aron Gombas _Midori_
Community Champion
August 4, 2023

Are you executing the script with ScriptRunner?

If so, then for the first look, you are trying this correctly. Can you try if

it.key

instead of

it.Key

works better?

Markus W_ BENES
Contributor
August 4, 2023

Thank you for your anwer; if i try it also in small letters i get the following message:

Something went wrong: MissingPropertyException

No such property: key for class: com.riadalabs.jira.plugins.insight.services.model.LegacyObjectBean Possible solutions: id

if i take it.id i get as i can see the process id; i coded the follwing function that is still working; but i think there is a much better way; getId() only works if i define the empty result variable before:

def returndevice(devicename) {

     def result = ""
     Assets.search('"Devices" IN ("'+ devicename +'") ORDER BY Start ASC').each {
     result = it.getId()
     }

     return result

}

return returndevice

Suggest an answer

Log in or Sign up to answer