Custom fields support SIL script

A useful tool for getting the most support for Jira Product Discovery.

This script is designed to discover the custom field ID’s of the Product Discovery fields that are seeming hidden in the product. The script will attempt to create SIL aliases for these fields so that they may be used normally in the future scripts.

What it does

Part A: Finding the custom fields

Step 1: Dynamically search

This step will find all the Product Discovery projects and get the all the ideas from each project. Then it loops through every idea and gets the custom fields used in that submission. The idea being that the field needs to be populated to get the information returned, by searching every issue it has a high probability of finding all the fields.

The nice part about this step is that if Atlassian adds any new fields they will automatically be picked up automatically without modifying the script.

Step 2: Static/heuristic search

In the event that custom fields are not populated this step uses a predefined list of supported custom fields to search for the field ID.

image-20240227-222447.png

Notice the progress and output from the script is displayed in the console tab at the bottom of the SIL Manager (image above). The output from each step is marked.

Part B: Creating the SIL aliases

Now that the script has retrieved all the IDs for the custom fields, the next step is to create the SIL aliases. The alias name is dynamically generated using camel case. So, for example, if the custom field name is “Idea short description” the camel case alias would be ideaShortDescription.

image-20240227-222405.png

In the event that an alias can not be created, an error message is displayed in the output with a link to the documentation about how to create the alias manually. The exact code that should be used to create the alias manually is also displayed in the output. However, the main reason that such an error occurs is that the alias already exists so the first step should be to verify if the alias is already in the sil.aliases file.

What to watch out for

The script adds the new aliases directly to the sil.asliases file. On some rare occasions a line break may be missing from the end of the last line which will cause new lines to bump up against the last existing line (see the image below). This usually only occurs when someone manually deletes the line break. Since the aliases are combined they are not formed correctly and will not work as indented. It is a good idea to check this file after running the script.

There are some other things to watch out for that are described in the known limitations page. It is important to review this material as well.

Code

To run this code:

  1. Create a new file in the SIL Manager (right click on a folder)

  2. Copy and paste the code below into the new file

  3. Click the green run button at the top of the SIL Manager

  4. Watch it go!

This script was written in such a way that it will work on anyone's Jira Cloud instance and with any Product Discovery fields that it can find. Because of this the code is much longer than it really needs to be, the SIL language is much easier then the code below may make it appear.

struct _pdField { string name; string id; string alias; } function camelCase(string name) { string [] words = split(name, " "); string cc = toLower(words[0]); for(int x=1; x<size(words); x++) { string nextWord; for(int l=0; l<length(words[x]); l++) { if(l==0) { nextWord = toUpper(words[x][l]); } else { nextWord += words[x][l]; } } cc += nextWord; } return cc; } _pdField [] allPDFields; string dots = "."; runnerLog("Starting dynamic search of Jira Product Discovery fields:", true); for(string proj in allProjects()) { JProject p = projectObject(proj); if(p.projecttype == "product_discovery") { runnerLog(dots + " Scanning project <strong>" + proj + "</strong>", true); dots += "."; for(string issue in selectIssues("project = " + proj, 100)) { for(string af in arrayKeys(getIssueFields(issue, true))) { if(startsWith(af, "custom")) { string name = getCustomFieldNameById(af); allPDFields[name] = {name, af, camelCase(name)}; } } } } } runnerLog("Dynamic scan complete, <strong style=\"color:blue;\">" + trim(size(allPDFields)) + "</strong> fields found in scan.", true); runnerLog("<hr>", true); //--new section-- runnerLog(""); runnerLog("Starting heuristic search of Jira Product Discovery fields:", true); string [] knownFields = "Category|Customer segments|Documents|Goal|Idea archived|Idea archived on|Idea short description|Product Area|Rank|Request participants|Roadmap|Teams"; int added = 0; for(string k in knownFields) { _pdField test = allPDFields[k]; if(isNull(test.name)) { allPDFields[k] = {k, null, camelCase(k)}; runnerLog(k); added ++; } } runnerLog(".", true); runnerLog("..", true); runnerLog("...", true); runnerLog("Heuristic scan complete, <strong style=\"color:blue;\">" + trim(added) + "</strong> field(s) found in scan.", true); runnerLog("<hr>", true); //--new section-- runnerLog(""); runnerLog("Creating SIL aliases for Jira Product Discovery fields:", true); int success_count = 0; int error_count = 0; for(_pdField f in arrayStructSort(allPDFields,"name")) { boolean result = admAddCustomFieldAlias(f.name, f.alias); if(result) { runnerLog("<strong style=\"color:green;\">Success</strong>: SIL alias created for \"" + f.name + "\": <i>" + f.alias + "</i>", true); success_count ++; } else { string message = "<strong style=\"color:red;\">Error</strong>: The SIL alias for " + f.name + ": " + f.alias + " was not able to be created for an unknown reason."; message += " It's possible this occured because the alias already exists."; if(isNotNull(f.id)) { message += " The SIL alias for will need to created manually. See <a href=\"https://appfire.atlassian.net/wiki/spaces/PSJC/pages/496206151/Managing+Aliases+in+the+sil.aliases+File\">this page</a> for instructions."; message += " Insert the following text into the sil.aliases file:"; message += "<div style=\"width:25%;background: #b3bac5;margin-left: 25px;padding: 0.25em 5px;\">" + f.alias + "=" + f.id + "<div>"; error_count ++; } runnerLog(message, true); } } runnerLog("Done! <strong>" + trim(success_count) + "</strong> SIL aliases were created with " + trim(error_count) + " errors.", true);
Peacock