<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=949806081816595&amp;ev=PageView&amp;noscript=1">
Go Back

Power Scripts' SIL Scripting Is, Well, Powerful!

Vivian Escalante Vivian Escalante | January 18, 2022 | 2 MIN READ
Power Scripts, SIL, Scripting, Powerful, Live Fields, SIL Listeners, SIL Scheduler

Untitled-139

If you use Power Scripts, then you know that SIL scripting can be used for many scenarios - Live Fields, SIL Listeners, and SIL Scheduler are just a few. In this blog post, I'm going to focus on the SIL Validator functionality that makes fields required when a specific field is a certain value.

Let's talk about this specific scenario in which the SIL Validator can assist. It is understandable to not want to overwhelm the user with a lot of fields on a transition screen if it's not necessary, so our goal is to stop the user from proceeding only if fields need to be required. If the user selects "Yes" for "customfield_5," then "customfield_1" through "customfield_4" are made required by presenting an error message on the Close transition. 

The SIL language is quite simple and straightforward with its naming conventions, such as "isNull" and "getIssueFields," and has many helpful functions that allow the scripts to remain clean and efficient. 

The "getIssueFields" function returns an array of all of the fields present for the specified issue key. This way you can validate whether "customfield_5" is "Yes" and show the appropriate error message. In the sample script below, we use "issueType" as a standard system variable you need to validate.

Lastly, we return the error message that constructs a string of all the fields that are null and shouldn't be if "customfield_5" is "Yes". For example, if "customfield_1" and "customfield_2" are empty, and "customfield_5" is "Yes," then the error message would be "Mandatory fields not filled. Fields: customfield_1, customfield_2."

 

// Description: SIL script to make specific fields required if field "customfield_5" is "Yes" on the Close transition
string[] fields = getIssueFields(key);
if (fields["customfield_5"] == "Yes" && (issueType == "issuetypeA" || issueType == "issuetypeB" || issueType == "issuetypeC" || issueType == "issuetypeD")) {
    string message;
     
    if (isNull(fields["customfield_1"]) ) message += "Customfield_1, ";
    if (isNull(fields["customfield_2"]) ) message += "Customfield_2, ";
    if (isNull(fields["customfield_3"]) ) message += "Customfield_3, ";
    if (isNull(fields["customfield_4"]) ) message += "Customfield_4, ";
     
    if (!isNull(message) ) {
        message = substring(message, 0, length(message)-2);
        return false, "Mandatory Fields not populated", "Mandatory fields not filled. Fields: "+ message;
    }
}

This is the very edge of what Power Scripts can do. I encourage you to keep exploring and share your learnings with the world. There are many of us out here always looking for new ways to optimize our scripts. 

 

definitive guide to transitioning from itsm to esm

Recent Articles

Triggering a Script When a Custom Field Changes
Triggering a Script When a Custom Field Changes
At Isos, we encounter many situations where either clients or we would like to trigger a custom action or script when a custom field changes. With no out-of-the-box Jira solution, we have had to come...
Amanda Kirk Amanda Kirk 3 MIN READ
Read More
The Essential Guide to Migrating to ScriptRunner for Jira Cloud
The Essential Guide to Migrating to ScriptRunner for Jira Cloud
Our whitepaper takes a look at the root cause behind the differences between ScriptRunner for Jira and ScriptRunner for Jira Cloud, as well as key feature and functionality parity issues. It also...
Isos Technology Isos Technology 3 MIN READ
Read More
REST API Authentication Script
Overview This article is for anyone making basic Jira REST API calls that have not explored the use of sessions. While the ideas in this blog can also be used for tools like Postman and Paw, it is...
Isos Technology Isos Technology 4 MIN READ
Read More