I'm using a SIL script (Power Scripts for Jira), as a post function at transition, to create sub-tasks of a "main" task once it's approved by an approver. i.e. single issue/task is in the approver's queue, then, once approved, 12 sub-tasks are created relating to that initial task.
I'm able to create all the sub-tasks, but have been unable to update additional fields of the sub-tasks that are not defined as part of the createIssue() routine.
startDate and endDate (custom fields customfield_10400 and customfield_10401, respectively, in the code snippet below). Once the SIL script has created the sub-task, how do I directly address and update these 2 custom fields per sub-task? Currently I'm using subTaskKey1.customfield_10400 =, where subTaskKey1 is the sub-task's key created by createIssue(), but it's not working; the start & end date values are not updated.
Do I need to include a reference to the project, and/or to the main task's key, similar to:
projID.mainBuildKey.subTaskKey1.customfield_10400 = ?
Thank you, in advance, for any assistance.
Code sample:
string mainBuildKey = key;
string issueSummary;
string issuePriority = "Minor";
string issueDescription;
string issueProject = "WIB";
string siteCode = customfield_10310;
string issueType = "Sub-Task";
string[] custom_fields_mapping = "customfield_10306|customfield_10307|customfield_10310|customfield_10400|customfield_10401"; //cust name, facil location, site code, start date, end date
// 1st subtask - VM Req (dev, qa, prod as needed)
issueSummary = "VM Request(s) to Platform Team - " + siteCode;
issueDescription = issueSummary;
string subTaskKey1 = createIssue(
issueProject,
mainBuildKey,
"Sub-task",
issueSummary,
issuePriority,
issueDescription, // Description same as issueSummary
{}, // no components
currentDate() + "3d", // DueDate - Platform Team 3 days to provide new VMs
"24h",// ~3 day/24 hour estimate on VM creation
{}, // issue security not set
custom_fields_mapping
);
linkIssue(subTaskKey1, mainBuildKey, "Relates");
subTaskKey1.customfield_10401 = subTaskKey1.dueDate; //set endDate to match dueDate
subTaskKey1.customfield_10400 = subTaskKey1.dueDate - "3d"; //set startDate to 3 days prior to endDate
Hello,
I think your code should look like this:
string mainBuildKey = key;
string issueSummary;
string issuePriority = "Minor";
string issueDescription;
string issueProject = "WIB";
string siteCode = customfield_10310;
string issueType = "Sub-Task";
string[] custom_fields_mapping = "customfield_10306|customfield_10307|customfield_10310|customfield_10400|customfield_10401"; //cust name, facil location, site code, start date, end date
// 1st subtask - VM Req (dev, qa, prod as needed)
issueSummary = "VM Request(s) to Platform Team - " + siteCode;
issueDescription = issueSummary;
string subTaskKey1 = createIssue(
issueProject,
mainBuildKey,
"Sub-task",
issueSummary,
issuePriority,
issueDescription, // Description same as issueSummary
{}, // no components
currentDate() + "3d", // DueDate - Platform Team 3 days to provide new VMs
"24h",// ~3 day/24 hour estimate on VM creation
{}, // issue security not set
custom_fields_mapping
);
linkIssue(subTaskKey1, mainBuildKey, "Relates");
%subTaskKey1%.customfield_10401 = subTaskKey1.dueDate; //set endDate to match dueDate
%subTaskKey1%.customfield_10400 = subTaskKey1.dueDate - "3d"; //set startDate to 3 days prior to endDate
Thank you, Alexey.
It looks like the change was the addition of the %s around a variable here:
%subTaskKey1%.customfield_10401 = subTaskKey1.dueDate; //set endDate to match dueDate
%subTaskKey1%.customfield_10400 = subTaskKey1.dueDate - "3d"; //set startDate to 3 days prior to endDate
correct?
So the % is necessary to reference some variables, at some times, but not always? i.e. the subTaskKey1 variable reference after the equal-sign does not get %, nor earlier in the script ?
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
key is a standard variable in SIL, that is why you do not need to put % before and after. But if you get a string with a key, then you need to put % before and after. You can find an example here:
https://confluence.cprime.io/display/SIL/Variable+resolution
Does your script work now?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the delay; I was tied up with other things yesterday.
Unfortunately the script doesn't work now. Before I updated those variables, the script would run, and change the main issue' status to "in progress" when you hit the Approve button.
Now hitting the Approve button doesn't appear to do anything but approve the main ticket. At that point, clicking "Start Progress" runs the script, but it errors out immediately with "Exception while executing SIL program.... [SIL Error on line: 4, column 1] Field >> here it reports the value of the field and not the field name itself << cannot be matched against a standard field, a custom field, or an alias. What is it?"
None of the sub-tasks are created as they were previously, though with incorrect start-/end-dates.
Line 4 of the script doesn't reference the field with the error, though.
Line 4 reads: "string mainBuildKey = key;"
After the initial issue is created, should a reindex of the issue happen before any SIL scripts run and sub-tasks are created linked to that initial issue? How about after each sub-task's creation - should a reindex happen then? if so, what's the command/routine to trigger an issue's reindex via SIL?
The post functions' order, as they are now, is
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Forget most of that last reply - I found a typo that was causing the new error.
Start Date and End Dates are now coming across - thanks!
new issue, of course. the custom fields from the parent are no longer getting copied to the sub-tasks.
Anyway... is there a way to reindex with a SIL script? How about a pause/delay/wait-state?
thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is possible to make a reindex. There are three functions available:
admReindex - reindex for all issues,
admReindexIssue - reindex an issue,
admReindexProjects - reindex projects.
Do mean that you want to stop an execution of a script for some time? If so, it is not a good practice in programming. Why do you need it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I'll give admReindex* a shot.
I didn't want to stop the script, or have a prompt the user must respond to in order to continue executing, only to insert a brief pause (like sleep 5 - to pause it for 5 seconds before continuing on its own). Thought - creating 12 sub-tasks in one shot, then editing some of their fields - perhaps a "little pause" to allow the system a couple of seconds to make sure everything is linked up before moving to the next task?
Thanks, again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do not put sleeps into the code. Your Jira will be fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.