How to exit from the Scriprunner script

mohit panwar July 22, 2021

I need to exit from the scriptrunner script once the condition is matched.

if (!cnList) {
log.error("user already exist")
def reporter ="My comments"
//return commentMgr.getLastComment(issue)*.body
return commentMgr.create(issue,currentUser, "Error :: User $cFieldValue2 Onqid not found in LDAP. Please check the ONQid" , true)
return 0;
}

 

This piece of code is not working properly and iterating to the end of all functions.

I want to exit from the script once this condition is found please. A help will really be approtiated.

2 answers

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2021

It's never going to reach your "return 0".  The line above it already returns from the script no matter what, so it's stopping there.

mohit panwar July 23, 2021

Thanks for pointing that out.  This also not exiting from function.

Do i need to return some other variable ?

if (!cnList) {
log.error("user already exist")
def reporter ="My comments"
//return commentMgr.getLastComment(issue)*.body
return 0

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 24, 2021

Ok, that absolutely is "exiting from function", so I think I need more information.  Specifically:

What do you think "exiting from function" is?  I don't think I am thinking it is the same thing as you, so I'd like to check.  (To me, it means "stop on this line, execute no code past it, and hand back control to the function calling the script, saying 'I'm finished' to it")

What is this script trying to do?

Where is it running?

0 votes
mohit panwar July 22, 2021

Below is the function i am using.

 

def user_jira_creation()
{ }

mohit panwar July 22, 2021

return 0; not working.

Suggest an answer

Log in or Sign up to answer