Adding multiple watchers to a task with a postfunction

I have successfully used the following script to add multiple users as watchers to a task as a post function of a transition:

function SetWatchers() {

if(field1 == "ABC")

    watchers = addElement(watchers, "xyz1");

}

When I tried to add different options as below, I recieive an error which says "Encountered else in line xxx. Was expecting <EOF> :

   else {

if(field1 == "DEF")

    watchers = addElement(watchers, "xyz2");

    } else {

if(field1 == "GHI")

    watchers = addElement(watchers, "xyz3");

}

What am I missing?

 

2 answers

1 accepted

The answer is to remove the "else" from the script and it works fine.

Some braces, try this:

if(field1 == "ABC") {
    watchers = addElement(watchers, "xyz1");
}  else { 
    if(field1 == "DEF") {
    	watchers = addElement(watchers, "xyz2");
    	} else {
		    if(field1 == "GHI") {
		        watchers = addElement(watchers, "xyz3");
		    }
    	}
    }

HTH,

Alexandra

The additional brackets returned more errors, but removing "else" did work.

A follow-up question - do you know how I can define more than one watcher?

watchers = addElement(watchers, "xyz1" + "xyz2"); does not work and does not add any watchers at all.

if i put

if(field1 == "ABC")
    watchers = addElement(watchers, "xyz1");
    watchers = addElement(watchers, "xyz2");
} {
if(field1 == "DEF") {
    watchers = addElement(watchers, "xyz3");
}    

The additional watcher is added to ABC, but also to DEF and any subsequent field1's.

What several errors do you get? Create an array with the watchers you want to add and then use arrayUnion  to add them all to watchers.

Multiple Users: I tried by calling a string where I defined users per each option for field one, but that behaved the same way as just adding another user to the the Watchers = watchers = addElement(watchers, "xyz1" + "xyz2");  I will try creating an array tomorrow and get back to you.

Error messages with additional brackets: 

image2016-5-24 16:58:48.png

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,781 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot