Automation: Advanced field editing for adding to array

Alena Samruk January 6, 2021

Hi guys,

I have custom field Viewers. It's an array of Jira users. One issue can have many users in Viewers field. 

I need to add automation to add all users from parent Viewers to child Viewers.

 

Could you please help me to specify an additional field correct? 

 

That's how I already did it:

Screenshot_5.png

 

 

But it doesn't work. Log says:

Screenshot_6.png

 

1 answer

0 votes
Bill Sheboy
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.
January 6, 2021

Hi @Alena Samruk 

A couple of things to try would be to add a Log action before you set the field to see what that call to asJsonStringArray is returning.

Next, perhaps try just set it directly (without the coversion to the array) if both Viewers fields are list fields.

Best regards,

Bill

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 7, 2021

I agree with Bill, you should just try the built in function to copy value from Parent issue. It even has the option to "[x] Add to existing values" in case you don't want to overwrite any subtask viewers:

Screen Shot 2021-01-07 at 1.13.28 PM.png

Alena Samruk January 11, 2021

Hi @Bill Sheboy , thanks for the answer!

asJsonStringArray is returning list of users, for example:

triggerIssue.viewers.asJsonStringArray: ["testuser","samruk"]

 

I tried to set it directly:

{
"edit": {"viewers":"{{triggerIssue.viewers}}"}
}

And get an error in the log:

No fields or field values to edit for issues (could be due to some field values not existing in a given project)

 

So it still doesn't work( 

 

 

Hi @Darryl Lee  thanks for the advice. I can't choose field Viewers using Built-in function. That's why I use the Advice section. But I saw on your screen you could choose Viewers field, how did you do it?

Screenshot_7.png

Bill Sheboy
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.
January 11, 2021

Hi @Alena Samruk 

You may need to use the custom field number/name in your JSON rather than the people-friendly name, Viewers.  Please talk to your instance admin to learn the custom field name and then try that for the edit.

__Bill

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2021

@Alena Samruk

Are you running on Cloud, Server, or Data Center? If Server/Data Center, what version?

Here's what my Viewers custom field looks like:

Screen Shot 2021-01-11 at 9.12.39 AM.pngBill mentioned that you could talk to your instance admin to get the custom field name/number. Do you not have full global rights on this Jira instance, but just project? I wonder if that's the limitation you're running into.

https://confluence.atlassian.com/automation/permissions-for-project-automation-993924702.html

Like Bill Sheboy likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2021

Oh, I forgot to mention, I'm testing this on Cloud. I tried with just Project Admin rights, and could still see the Viewers field. Also, interestingly, it didn't seem to matter that Viewers is not on the Screens for my test project.

I guess one other thing to ask is whether Viewers are in a valid Field Configuration Context for your project.

I just restricted my Viewers field to a different project, and ... Nope, I still see the field. I'm at a loss. Maybe it's a Server/DC thing.

Bill Sheboy
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.
January 11, 2021

How about this syntax which should iterate over the trigger issue's viewers and add their JSON using the id values:

{
"fields": {
"viewers": [
{{#triggerIssue.viewers}} { "id": "{{accountId}}" } {{^last}},{{/}} {{/}}
]
}
}

Here's the documentation on the advanced JSON edit:

https://support.atlassian.com/jira-software-cloud/docs/advanced-field-editing-json/

Like Darryl Lee likes this
Alena Samruk January 11, 2021

@Bill Sheboy  thanks for the advice.

I've tried custom field number/name before, and it didn't work too.

Syntax which you wrote works! But unfortunately not as expected, it deletes all Viewers from a child task. Will try to modify it but I'm really not good in JSON so hope your link will help :) Thanks!

 

@Darryl Lee  thanks for the answer. I use Server Jira, have admin rights. Viewers field is a Global custom field and available for all projects. I think you can see it because of the Cloud version.

Bill Sheboy
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.
January 12, 2021

@Alena Samruk   Sounds good...  To help diagnose why the field is being cleared rather than filled, consider posting the new id values with the Log action rather than updating the field.  That should rule out part of the cause.

{{#triggerIssue.viewers}} { "id": "{{accountId}}" } {{^last}},{{/}} {{/}} 
Like Daniel Alonso likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2021

@Alena Samruk I was going to suggest reaching out to Support, because this is weird. But then I dug around. Is this a Next-Gen Project? As with many things (:-( that's probably the problem:
https://jira.atlassian.com/browse/JRACLOUD-75792

I wonder if "add" would work here, as documented in that bug. So then:

{
"update": {
"viewers": [
"add": {{#triggerIssue.viewers}} { "id": "{{accountId}}" } {{^last}},{{/}} {{/}}
]
}
}

If not, then maybe you could try *ALSO* iterate over the existing viewers:

{
"fields": {
"viewers": [
{{#issue.viewers}} { "id": "{{accountId}}" }, {{/}}
{{#triggerIssue.viewers}} { "id": "{{accountId}}" } {{^last}},{{/}} {{/}}
]
}
}

Suggest an answer

Log in or Sign up to answer