Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Dynamically assign value to Affected Services field via JSM Automations

Boris Zozoulia
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.
June 17, 2021

Hello Community

 

Is there a way to copy one field value to another, where source field is text, and destination (to copy it to) is a drop down like Affected Services, or any other Insights field.

The idea is:

My form has a Dropdown of X values, which contain List of Services i want users to use on this form. My Insight Services list contains Y items, thats why I want users to restrict it to be able to select only some of the services.

Via Automation i want to get that value of Drop down list and "Assign it" to Affected Services form field which is and Insights object field.

 

2 answers

1 accepted

5 votes
Answer accepted
Boris Zozoulia
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.
June 18, 2021

@Alex van Vucht (GLiNTECH) thanks for your response.

 

However it does not appear to work, setting value  {{issue.Service Objects.Name}} in the selected Affected Services, does nothing (affected services tries to run autocompletion, nothing is found, and the input box is cleaned up.

Instead, i have selected

  1. When: Value changed for Service Objects
  2. If/else block:
    1. If: Service Objects are empty
    2. Then: Edit issue: Affected Services: Blank, ie. clear this field
    3. Else:
    4. Then: Edit issue: DO NOT Choose fields to set
    5. Click on More options, and under Advanced, specify:
      {

      "fields": {

      "Affected services":[{"id": "{{issue.Service Objects.Service ID}}"}]

      }

      }

       

If you Service Objects field (which is a custom Insights object field type) accepts multiple values, you might as well wanna use Jira's loop-over-list template stanzas: 

{
"fields": {
"Affected services":[{{#issue.Service Objects}}{"id":"{{Service ID}}"}{{^last}},{{/}} {{/}}]
}
}

if you don't want to use loop stanzas we can rather use this shorthand

{
"fields": {
"Affected services":{{issue.Service Objects.Service ID.asJsonObjectArray("id")}}
}
}

this documentation is taken from: https://support.atlassian.com/jira-software-cloud/docs/advanced-field-editing-json

Ed Letifov _TechTime - New Zealand_
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.
March 16, 2022

Hello,

For the sake of others who may (by miracle) find this post, some helpful links and hints:

1) Please see and vote on this feature request: https://jira.atlassian.com/browse/JSDCLOUD-10340

Affected Services though it looks like an Insight Object custom field, and has an Insight schema backing it up, is in fact using Opsgenie API and Opsgenie's service id's for the items. Thankfully Opsgenie service id is stored in the Insight object as an attribute.

We had to use "loop stanzas" as the "shorthand" notation didn't work, kept successfully getting some numeric id value, instead of the Opsgenie Service ID attribute.

2) In our case the duplicate Insight Object custom field Services Affected is based on the same Insight schema, and is presented on the Issue Create scheme, together with dependent Insight Object custom fields.

Automation on create syncs the value to Affected Services.

3) Please note, the Affected Services field does behave differently in UI than the Insight field based on the same Insight schema, as it shows mode details from JSM/Opsgenie, so we preferred to keep that field on the edit and view screens, and hide the "parent" Insight field from these, only displaying it on create screen for the purposes of dependent drop-down functionality.

This does however then require addition setup in Automation to keep Affected Services and the "parent" Insight field in sync in the other direction, so if the affected service changes later in JSM ticket workflow, the dependent Insight field displays correct objects that correspond to the "sub-options". This automation rule is configured to run on Edit and Transition, and not be invoked by other rules.

Obviously, none of this is instantaneous, and is just one major kludge for something that should be so simple, and could have been avoided if the dependent Insight custom field could be dependent on Affected Services directly. 

Phillip Goffin October 9, 2023

I'm hoping someone can help me here.  I'm creating change requests via automation from Jira asset objects. 

I need the change request to include any "Affect Services" listed on the asset object. 

I use below in automation "more fields" to add Services to the change request -

{
"fields": {
"Affected services":[{{#object.Affected Services}}{"id":"{{Service ID}}"}{{^last}},{{/}} {{/}}]
}
}

This works great when the object has multiple "Affected Services" but if the object only has a single service I receive "Error while parsing additional fields. Not valid JSON."

??

Renatão November 21, 2023

@Phillip Goffin , I also jumped into the same article, but my problem is not completely solved.

In my case, I need to have a branch with N objects. I need to add them one by one to the Affected Services field. For each one, I´m using the sintax bellow in the advanced edit field:

 

{
"update": {
"Affected services" :
[{"set":[
{{#lookupObjects}}
{"id":"{{Service ID}}"}
{{^last}}, {{/}}
{{/}}
]
}]
}
}

 

Otherwise, only the last item is added to the list. It seems that each command (each branch loop) overrides the previous content.

Phillip Goffin November 22, 2023

@Renatão I'm not quite sure what you are trying to achieve and I am no way an expert in this but this is how I added multiple services to "Affected Services" field in an issue.  Hope this helps.

Retrieve the custom field ID for Affected services

 

auto 3.JPG

 

auto 4.JPG

Use the custom ID to look up objects in "Services" assets

 

 auto1.JPG

Complete the automation

 

auto2.JPG

{
"fields": {
"Affected services": [
{{#lookupObjects}}
{"id": "{{Service ID}}"}{{^last}},{{/}}
{{/}}
]
}
}

0 votes
Alex van Vucht (GLiNTECH)
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.
June 17, 2021

I've been doing some work with the Affected Services field recently and it's a little special. It uses the OpsGenie API, not the Insight Cloud API.

You'd have to create a separate Insight Object custom field for the Services schema so that you can then set an IQL query to restrict the options. I'll call this field "Service Objects" but you can call it whatever you like.

Try this:

  1. When: Value changed for Service Objects
  2. If/else block:
    1. If: Service Objects are empty
    2. Then: Edit issue: Affected Services: Blank, ie. clear this field
    3. Else:
    4. Then: Edit issue: Affected Services: {{issue.Service Objects.Name}} 

I'm not too sure how well this will work if multiple services are selected. Working with smart values for multiple selections gets messy, especially with Insight objects. Get it working first for a single selection then expand from there.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events