You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 2
Next »
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.
Step 2: 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.
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
As you may know, there are two ways to create
Code
To run this code:
Create a new file in the SIL Manager (right click on a folder)
Copy and paste the code below into the new file
Click the green run button at the top of the SIL Manager
Watch it go!
SIL script to enable custom field support for Jira Product Discovery
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);