Update Portfolio Parent Link using REST API
This script is out of date and no longer relevant. It predates the existence of the HTTP routines which allow SIL to make REST calls directly.
Also, now the portfolio parent field is directly supported.
We are leaving this article in place as a reference.
Some fields just can't be set using the regular Jira REST API, the Portfolio Parent Link is one of those fields. Fortunately, you can easily create a script that uses the Power Scripts REST Service to do the job when the Jira API can not.
To start, we need to the script that will run when called by the REST Service. This script is actually very generic, any custom field can be set using a simple script like this:
string field = argv[0];
string value = argv[1];
%field% = value;
This is an example Curl script that calls the Power Scripts REST Service to run the script.
curl -X POST -u admin:admin http://localhost:8080/rest/keplerrominfo/refapp/latest/async-script/runScript \
-H 'Content-Type: application/json' \
-d '{"source":{
"type": "FILE",
"code": "updateCustomField.sil"
},
"properties": [{
"key": "sil.issue.key",
"value": "TP-123"
}],
"args": ["customfield_12345", "PORT-456"]}'
To adapt the provided Curl script, follow these steps:
Update the username and password with a valid user account. This is set at the beginning after the
-u
parameter.Update the Jira base URL. The address format is
<your_base_url>/rest/keplerrominfo/refapp/latest/async-script/runScript
.Ensure the name and path of the script are correct. This is set in the "code" field in the JSON data. In the provided example, the script is named "updateCustomField.sil."
Update the key of the issue that will be updated. This is set in the "value" field in the JSON data. In the provided example, the issue key is "TP-123."
Update the custom field ID of the Parent Link field or the name of the SIL alias if previously set up. This is passed in the "args" field array in the JSON data. In the provided example, the ID is "customfield_12345."
Update the key to which the issue should be linked (the parent). This is the second value in the args array. In the provided example, the parent link is "PORT-456."