SIL/Power scripts - How to set KPOtion (Power Custom Fields) field value in createIssue() routine?

Błażej O_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2020

Hi,

I have a Power Custom Field on create issue screen. This is a field required by the validator - it has to be set, otherwise Jira won't create the issue.

If I try to create the issue programmaticaly using createIssue() routine we get an error:

/rest/keplerrominfo/refapp/latest/async-script/checkScript [c.k.j.c.i.routines.issue.CreateIssueRoutine] Cannot save new issue; error was com.keplerrominfo.jira.commons.hostapp.JiraOperationException: Cannot save new issue; error was com.keplerrominfo.sil.lang.IncompatibleValueException: Cannot convert array [STRING[]] {here_is_my_string} to structure KPOption. Different number of elements

I have tried creating mappings using two-dimensional array, or string with "|" in the middle - nothing helps:

string[][] CFmappings = {"assignee", "me", "my_PCF_field_name", {"my_pcf_field_label","my_pcf_field_value"}};
//string[] CFmappings = {"assignee", "me", "my_PCF_field_name", "my_pcf_field_label|my_pcf_field_value"};
string this_test_key = createIssue("TEST", "", "Task", "Test", "Minor", "Test", "", "", "", "", CFmappings);
runnerLog(this_test_key);

How can I create issue using SIL if there is a PCF field with validation on create?

 

EDIT: clarification/wording

2 answers

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2020

Hello @Błażej O_ ,

If a field is required then an issue can not be created via UI or REST API if the required field is not set, but in SIL you can still create such an issue. That is why your code would be like this:

KPOption nopt;
nopt.label = "my_label";
nopt.value = "my_value";
string[] CFmappings = {"assignee", "me"};
string this_test_key = createIssue("BUS", "", "Task", "Test", "Medium", "Test", "", "", "", "", CFmappings);
%this_test_key%.#{my_PCF_field_name} = {nopt};
Błażej O_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2020

Hi,

I have already tried this approach and I use it successfully whenever there is no validation on issue creation, however this does not work for validators on issue create.

Your code produces following errors:

/rest/keplerrominfo/refapp/latest/async-script/checkScript [c.k.j.c.hostapp.impl.KIssueServiceImpl] Cannot save new issue; error was com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow: 
com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow:
(...)
Caused by: [InvalidInputException: [Error map: [{=Please fill field My_PCF_field_name}]] [Error list: [[Please fill field My_PCF_field_name]]]
(...)
/rest/keplerrominfo/refapp/latest/async-script/checkScript [c.k.j.c.i.routines.issue.CreateIssueRoutine] Cannot save new issue; error was com.keplerrominfo.jira.commons.hostapp.JiraOperationException: Cannot save new issue; error was com.atlassian.jira.exception.CreateException: Error occurred while creating issue through workflow:
/rest/keplerrominfo/refapp/latest/async-script/checkScript [c.k.sil.lang.SILUtils] [SIL Error on line: 6, column: 16] Field >><< cannot be matched against a standard field, a custom field or an alias. What is it?
/rest/keplerrominfo/refapp/latest/async-script/checkScript [c.k.r.sil.impl.AbstractSimpleLanguageService] Exception while executing SIL program >>null<<: [SIL Error on line: 6, column: 16] Field >><< cannot be matched against a standard field, a custom field or an alias. What is it?
com.keplerrominfo.sil.lang.SILInfoException: [SIL Error on line: 6, column: 16] Field >><< cannot be matched against a standard field, a custom field or an alias. What is it?

It obviously cannot update PCF field with KPOption value, because it cannot access the field on the issue, because the issue actually never gets created.

 

To clarify, the field is required by the validator (power script one of course ;) ), not by the jira field config scheme.

 

So, any workardounds for valdiators? :)

Also, setting the field value AFTER the issue gets created is far from ideal situation, because on the target issue itself there are post-functions that depend on the PCF field value.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2020

I believe that if you want to make it work as you expect it to work, you should create a ticket with cprime support but I think it will not be a fast fix.

Or you can add a custom field called SIL created. If this field is set to 0 by default, then your validator will check the issue, if to 1 then your validator will not check the value.

You will set the SIL created field in your createIssue method to 1. And then the validator will not check it. Then you will set a value to your PCFU field and then in your sil script you will launch routines which should be executed by post functions.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2020

or use Jira Rest Api to create an issue.

0 votes
Alexey Matveev August 7, 2020

EDITED

Suggest an answer

Log in or Sign up to answer