UI Action - How to control multiple field value in the system properties.

Alpha_K
Tera Contributor

Hi All,

 

In the sctask  we have a UI Action for story creation. when we click  that UI Action story will get created .

 

where I have a use case

1.if the assignment group is network then in the story following fields need to get updated

 

assignment group as "Network Admin", then CI - Network and product is Network

 

2. if the assignment group is wintel then story following fields  need to get updated

 

assignment group as" Wintel Admin", then CI- Wintel and product is Wintel.

 

Instead of hard coding of sys id in the UI Action . I was trying via " System Properties".

 

where in the system property Value

 

I have given value as

 

[
  {
    "assignment_group": "Network",
    "product": "Network",
    "cmdb_ci": "Network"
  },
  {
    "assignment_group": "wintel",
    "product": "wintel,
    "cmdb_ci": " wintel"
  }
]

 

In the UI Action:

 

var arr = gs.getProperty('propertyname');
var grp = current.getDisplayValue('assignment_group');
for(var i=0;i<arr.length;i++)
{
if(arr[i].assignment_group == grp)
{
current.setValue(arr[i].product);      
current.setValue(arr[i].theme);        
current.setValue(arr[i].cmdb_ci);      
current.update();
}
}
 
Currently this is not working can some one please check and suggest
 
 
Thanks & Regards,
Alpha

 

 

3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

Two quick things to check. In the first line, are you using 'propertyname' generically so not to put the real name? If not, then you need to change that to the name of your property. Secondly, I'd check the values in your property for assignment_group and make sure those values actually match the display value from your record's assignment group, since they will be case sensitive as you are not converting the value to lowercase.

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Najmuddin Mohd
Mega Sage

Hi @Alpha_K ,

The code you have written is of type Object and work with variables defined as objects.
But, in the system properties, you do not have type as Object. I believe you have selected as String.

NajmuddinMohd_0-1731523074617.png

Which should not be the case.

So, you should convert this String into Object in the code and the code should be written in only one line as the indention does not work when converting into Object.


NajmuddinMohd_1-1731523935975.png

 

 

[{"assignment_group": "Network", "product": "Network","cmdb_ci": "Network"},{"assignment_group": "wintel","product": "wintel","cmdb_ci": "wintel"}]

 



NajmuddinMohd_2-1731523960295.png

 

var arr1 = gs.getProperty('Community.Property');

// Parse the string into an actual JavaScript array
var arr = JSON.parse(arr1);

for(var i=0;i<arr.length;i++)
{
if(arr[i].assignment_group == "Network")
{
	gs.info(arr[i].product);
}
}



*** Script: Network

 



Another option is to create Individual Properties.

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

Juhi Poddar
Kilo Patron

Hello @Alpha_K 

There are few mistakes:

  1. Make sure the values set in property and the display value follows the same case. Here 'Network' and 'wintel' are in different case therefore cross check it once again with the display value.
  2. Since the property is set as a string, parsing the string becomes mandatory.
  3. syntax: current.setValue('field_name' , value);  field_name is missing.
  4. The 'Theme' is not set in the property. If not needed then remove it from the code as well.

The updated script:

 

 

var arr1 = gs.getProperty('propertyname');
var arr = JSON.parse(arr1);

var grp = current.getDisplayValue('assignment_group');
for (var i = 0; i < arr.length; i++) {
    if (arr[i].assignment_group.toLowerCase() == grp.toLowerCase()) {
        current.setValue('product', arr[i].product); //set the field name Product
        current.setValue('theme', arr[i].theme);  //set the field name Theme
        current.setValue('cmdb_ci', arr[i].cmdb_ci); //set the field name CI
        current.update();
    }
}

 

 

I hope this solution helps you resolve the issue.

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar