SIL - Copy links from parent

Hello.

I'm struggling with a weird problem with SIL custom field.

What I'm trying to do is to copy links from parent right away on creation of subtask. However the tricky part is I want to copy only the links to issues with creation date after some date set in the customfield.

Here is my code:

string[] mlinked_issues = linkedIssues(parent);
string mthis_key = key;
string mlink_key;
string mindex = size(mlinked_issues);

 
for(number i=0; i<=mindex; i=i+1)
{
    mlink_key = mlinked_issues[i];
    logPrint("ERROR", "KEY: " + mlink_key + "--------- if(" + %mlink_key%.created + " >= " + %mthis_key%.customfield_10900 + ");");
    if (%mlink_key%.created >= %mthis_key%.customfield_10900)
    {
        logPrint("ERROR", "I'm inside IF statement!");
        linkIssue(key, mlink_key, "Relates");
    }
}

What is weird about it: earlier I have had the script without "if" statement and it worked perfectly copying ALL links from parent. Now, when I added "if" statement, it is still copying all links even though it is NOT entering the "if" statement. I even removed completely the "linkIssue" command... and it still copy all links from parent. Don't ask me how, I am completely confused.

Logs show that it shouldn't enter the "if" statement as well as some errors:

2013-08-14 17:26:55,034 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [commons.sil.routines.LogPrintRoutine] KEY: DOK-792--------- if(2013-08-07 14:01:00 >= 2013-08-14 17:13:40);
2013-08-14 17:26:55,040 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [commons.sil.routines.LogPrintRoutine] KEY: DOK-793--------- if(2013-08-12 14:09:51 >= 2013-08-14 17:13:40);
2013-08-14 17:26:55,047 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [commons.sil.routines.LogPrintRoutine] KEY: DOK-795--------- if(2013-08-14 11:46:51 >= 2013-08-14 17:13:40);
2013-08-14 17:26:55,053 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [commons.sil.routines.LogPrintRoutine] KEY: DOK-796--------- if(2013-08-14 11:47:04 >= 2013-08-14 17:13:40);
2013-08-14 17:26:55,059 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [commons.sil.routines.LogPrintRoutine] KEY: DOK-797--------- if(2013-08-14 11:47:14 >= 2013-08-14 17:13:40);
2013-08-14 17:26:55,064 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [jira.commons.ivm.IssueVariable] Variable >>.created<< is not a custom field.
2013-08-14 17:26:55,064 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [jira.commons.sil.SILUtils] [SIL Error on line: 10, column: 63] Variable >>.created<< is not a custom field.
2013-08-14 17:26:55,064 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [jira.commons.silrunner.UnifiedSilRunner] Exception while executing SIL program >>SilScript custom field Default Configuration for SIL - Kopiowanie linkow<<
com.keplerrominfo.jira.commons.sil.SILInfoException: [SIL Error on line: 10, column: 63] Variable >>.created<< is not a custom field.
(...)
Caused by: com.keplerrominfo.jira.commons.sil.SILException: Variable >>.created<< is not a custom field.
(...)
2013-08-14 17:26:55,067 ajp-bio-8009-exec-3 ERROR ***user_login*** 1046x30461x1 3uqcia ***user_IP*** /browse/ITEM-709 [plugins.keplercf.silscriptcf.SilScriptCFType] Exception occurred while executing SIL Script for custom field Default Configuration for SIL - Kopiowanie linkow on issue ITEM-709
com.keplerrominfo.jira.commons.sil.SILException: Exception while executing SIL program >>SilScript custom field Default Configuration for SIL - Kopiowanie linkow<<
(...)
Caused by: com.keplerrominfo.jira.commons.sil.SILInfoException: [SIL Error on line: 10, column: 63] Variable >>.created<< is not a custom field.
(...)
Caused by: com.keplerrominfo.jira.commons.sil.SILException: Variable >>.created<< is not a custom field.
(...)

I will appreciate any help on this issue. I'm quite new to using SIL, and probably I'm making some newbie mistakes, yet I can't find them for more than 6 hours already...

3 answers

1 accepted

Hi,

It's the for condition that is wrong. It should be i < mindex instead of <=. The <= will do an extra iteration on a null element and that's the one that fails. It still creates the issue links because it works ok until the last iteration when it fails.

That's exactly what was wrong, thanks!
Sorry for such late acceptance of the answer.

Hi Blaze,

I want to do this, minus the part about the dates. How do I create a field to which I can assign this code? I'm just wanting to copy the parent-issue's Confluence links down to the sub-tasks upon creation.

Thanks!

Hi Isaac,

You should add a SIL post-function on the Create Issue transition with your SIL code and publish the workflow.

You should add your code inside an if block, to execute only for subtasks:

if(!isNull(parent)) { ... }

Kind Regards,

Alex

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,990 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot