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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.

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.

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.

@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?

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

@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;

}

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

@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. 

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

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.

@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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you