Iterate string to set assignee

Originally asked by Jose Pablo Alpizar Hidalgo on 25 May 2022 (original question)


I need the Jira tickets assigned to different based on the Summary field coming from ADO. I tried the below script but it seems to have a syntax error and does not allow me to save. But hopefully, this will show you what I try to achieve.
I need this in Jira Cloud Incoming script.
------------------------------------------------------------------------------------------
def AssigneeSVT = nodeHelper.getUserByEmail(“SVTEmail@abc.com.au”)
def AssigneeSIT = nodeHelper.getUserByEmail(“SITEmail@abc.com.au”)
def AssigneeUAT = nodeHelper.getUserByEmail(“UATEmail@abc.com.au”)

if (replica.summary.substring(0,3) = “SVT”) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeSVT
}

if (replica.summary.substring(0,3) = “SIT”) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeSIT
}

if (replica.summary.substring(0,3) = “UAT”) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeUAT
}


Answer by Chama on 19 December 2022

Hi,

Instead of “startsWith” can I use “contains”? Will it scan the string to find a spefic value.

I tried with

if (replica.summary.contains(“VCCT”))

But it didnt work.

Appreciate any help on this.

Thanks


Answer by Ariel Aguilar on 25 May 2022

Hi you may try the following:

def AssigneeSVT = nodeHelper.getUserByEmail("SVTEmail@abc.com.au")
def AssigneeSIT = nodeHelper.getUserByEmail("SITEmail@abc.com.au")
def AssigneeUAT = nodeHelper.getUserByEmail("UATEmail@abc.com.au")

if (replica.summary.startsWith("SVT")) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeSVT
}

if (replica.summary.startsWith("SIT")) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeSIT
}

if (replica.summary.startsWith("UAT") {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: AssigneeUAT
}

Kind regards,

Ariel


Comments:

Chama commented on 31 May 2022

Hi Ariel,

Many thanks for your response. It worked!

Regards

Francis Martens (Exalate) commented on 31 May 2022

Small nit
You will perform 4 ‘getUserByEmail’ this way while with following code, you only will perform 2 queries (max). In case of performance concerns …


if (replica.summary.startsWith("SVT")) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: nodeHelper.getUserByEmail("SVTEmail@abc.com.au")
}

if (replica.summary.startsWith("SIT")) {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: nodeHelper.getUserByEmail("SITEmail@abc.com.au")
}

if (replica.summary.startsWith("UAT") {
issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email) ?: nodeHelper.getUserByEmail("UATEmail@abc.com.au")
}
Chama commented on 19 December 2022

Sorry, meant to post this as an additional question, not an answer.

Instead of “startsWith” can I use “contains”? Will it scan the string to find a spefic value.

I tried with

if (replica.summary.contains(“VCCT”))

But it didnt work.

Appreciate any help on this.

Thanks