Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SIL Script - How to update the multiple group picker customfield based on the select list value ?

Sami Ahmed Shaik
Contributor
February 9, 2020

Hello there,

Consider the following scenario. 

 

We have 2 custom fields - "Department" & "CC Departments". 

Department - Single Select Value (Transition Screen)

CC Department - Multiple Group Picker (Edit Issue Screen or View Issue Screen)

 

In the workflow, Department is on the self transition "Add Departments" - "New" -------> "New" where user selects the department. 

We are seeking a SIL script based on the department selection on the self transition, CC Department should be updated on "Edit Screen" or "View Issue Screen".

 

Regards,

Sami Ahmed Shaik.

1 answer

1 accepted

1 vote
Answer accepted
Andrew Laden
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.
February 10, 2020

Are you looking to dynamically update the screen in real time, or update the contents of the "CC Department" field in a transition based on the value of the Department field.

Sami Ahmed Shaik
Contributor
February 10, 2020 edited

Thanks for the reply @Andrew Laden .

We are looking to update the contents of the "CC Department" field only based on the value selected for the "Department" during the transition.

Andrew Laden
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.
February 11, 2020

So it sounds like a simple switch construct would work.

 

switch(Department) {
case "Human Resources":
#{CC Department} = {"Security", "Applications"};
break;
case "Applications":
#{CC Department} = {Security", "IT Management"};
break;
case "Maintenance":
#{CC Department} = {"Human Resources", "Security"};
}

Save that as a sil script and execute in your post function.

Sami Ahmed Shaik
Contributor
February 11, 2020

@Andrew Laden 

 

Thanks for the script. I tried to use the script in the following way but the script is not working.

 

string Department = "customfield_11705";
string CC = "customfield_12849";



switch(Department) {
case "RDS":
#{CC} = {"IRTI-RDS-Staff"};
break;
case "IFPC":
#{CC} = {"IRTI-IFPC-Staff"};
break;
case "IFCB":
#{CC} = {"IRTI-IFCB-Staff"};
break;
case "DG Office":
#{CC} = {"IRTI-DGOffice-Staff"};
break;
}

 

Please correct me where I am going wrong?

Andrew Laden
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.
February 12, 2020

You are mixing up 2 different formats in SIL

Generally in SIL, there are already pre-defined variables for any custom field based on the name of the custom field. So you dont need to define "Department" as a varaible, it i already there. The catch is if the custom field name has spaces in it, in which case you have to enclose it in #{..} 

So you don't need to define variables for CC and Department.

However, if you want to you can, you just have to reference the variable as %name%

So assuming your custom field is id 11705 and named "CC Department" the following would all work

customfield_11705 = {"IRTI-DGOffice-Staff"};  # field by ID number

#{CC Department} = {"IRTI-DGOffice-Staff"};  # Field by name

string ccdepartment = "customfield_11705"
%ccdepartment% = {"IRTI-DGOffice-Staff"};  # Defining a variable and referencing it.

 

 

See https://confluence.cprime.io/display/SIL/Variable+resolution for more information.

Like Sami Ahmed Shaik likes this
Sami Ahmed Shaik
Contributor
February 12, 2020

@Andrew Laden 

 

Thanks for the reply, I am getting the  following errors 

 

  • Variable >>Department<< is not defined!
  • [SIL Error on line: 6, column: 28] Incompatible possible types for ATTRIB: LHS = null, RHS = [STRING[]]
  • Variable >>CC Departments<< is not defined!
  • [SIL Error on line: 9, column: 28] Incompatible possible types for ATTRIB: LHS = null, RHS = [STRING[]]
  • Variable >>CC Departments<< is not defined!
  • [SIL Error on line: 12, column: 28] Incompatible possible types for ATTRIB: LHS = null, RHS = [STRING[]]
  • Variable >>CC Departments<< is not defined!

for the following script

 

switch(Department) {
case "STI":
#{CC Departments} = {"PRES-STI-DESK"};
break;
case "Prez Office":
#{CC Departments} = {"PRES-PRO-DESK"};
break;
case "SDGs":
#{CC Departments} = {"PC-Advisor-SDGs"};
break;

}
Andrew Laden
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.
February 14, 2020

Thats Odd, I just tested with the following code and it ran fine.

switch(Department) {
case "TSG":
#{CC Departments} = {"Department one", "Department two"};
break;
case "Applications":
#{CC Departments} = {"Department two", "Department three"};
break;
case "Maintenance":
#{CC Departments} = {"Department one", "Department three"};
}

Are you on an old version of SIL?

try using the customfield_id format just to see if that works.

Like Sami Shaik likes this
Sami Shaik
Contributor
February 16, 2020

@Andrew Laden 

 

Thanks so much & appreciate your help, the script works by using "customfield_id". 

I am wondering if we have the same scenario but instead of a single selection of DEPARTMENTS if the user has to select MULTIPLE DEPARTMENTS and based on the selection of MULTIPLE DEPARTMENTS post function should add MULTIPLE GROUPS then how can we do this? Consider the below scenario requirements 

TO Department --> Multi-Select Custom Field

CC Department --> Multi-Group Pickers. 

Sami Shaik
Contributor
February 19, 2020

Thanks to @Andrew Laden , Marking this question as answered. 

Andrew Laden
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.
February 25, 2020

You are going to want to use the "elementExists" function.

So instead of using a switch..case statement, you will probably just want a set of i"if" statements.

 

if ( elementExists(#{Department},"STI")) {
    #{CC Departments} = {"PRES-STI-DESK"};
}

Depending on how you write it you may end up matching multiple cases, so you probably want to use arrayAddElementIfNotExist to add to the CC Departments field

if ( elementExists(#{Department},"STI")) {
    arrayAddElementIfNotExist (#{CC Departments},"PRES-STI-DESK");
}

That way you would get the all of the departments that should be added.

You should take some time to really read through the SIL manual at https://confluence.cprime.io/pages/viewpage.action?pageId=6560282

It gives lots of good examples to work from.

Sami Shaik
Contributor
February 25, 2020

@Andrew Laden 

Thank you so much. I will try the script and will share the feedback by tomorrow.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events