Need to autopopulate the value in Change Request table based on a reference variable

cameron8
Tera Contributor

I have a situation where I need to set a choice field (doesnt have to be a choice, can be free text as well) to yes or no based on which configuration item is chosen. As an example - if someone selects an application that is marked as a SOX Compliant app as the configuration item the change is based upon, I need the "Is SOX?" field to auto-populate to "yes" or "No" based on the value of that field in the actual config item record. please see screenshots. 

 

is this something that I should do in flow designer? or can I do this simply within the change record?

Screen Shot 2024-10-15 at 11.54.22 AM.png

Screen Shot 2024-10-15 at 11.53.06 AM.png

Screen Shot 2024-10-15 at 11.52.28 AM.png

Screen Shot 2024-10-15 at 11.51.57 AM.png

Screen Shot 2024-10-15 at 11.51.50 AM.png

     

8 REPLIES 8

Voona Rohila
Kilo Patron
Kilo Patron

Hi @cameron8 

As per your screenshots, Is Sox is a mandatory field so you can write onChange Client script on Configuration item Field and get yes/no from CI Record.

1. If CI Value is empty then make isSox to None.

2. Once you set the isSox value from script

  • Make it read-only so that that user cannot update manually(This is as per your requirement)

Is "Sox Application Specific" field available on all the cmdb tables or specific tables?

  • If on specific tables then use GlideAjax to get that Value.
  • If on All the cmdb tables then you can use getReference() in your client script( Not a good practice)

 

getRefernce is not considered best practice because It brings the complete record details but we only need one, You can go with GlideAjax Approach.

 

Adding few links below, Try and let us know if you're stuck.

Glide Ajax Example

 

https://www.servicenow.com/community/developer-forum/populate-field-value-based-on-another-field-usi...

 

https://www.servicenow.com/community/developer-forum/glide-ajax-not-working/m-p/1381985

 

 

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

"sox application specific" is on the CMDB Application Table, possibly on others but for sure just on the appl table. as far as the script is concerned, how would you go about writing the onchange script to trigger off the CI field? any examples of how you'd do it?

Please check the links I provided, those are similar use cases.

https://www.servicenow.com/community/developer-forum/populate-field-value-based-on-another-field-usi...

 

https://www.servicenow.com/community/developer-forum/glide-ajax-not-working/m-p/1381985

 

Try and let us know if you're stuck.

 

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

I'm admittedly useless when it comes to writing scripts in servicenow is why I ask. pretty in the dark. 

 

script includes:

var Autopopulate = Class.create();
Autopopulate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

myfunction: function(){
var value = {}; // to store multiple values
var usr = this.getParameter('sysparm_is_sox');
var tab = new GlideRecord("cmdb_ci");
tab.addQuery("is_sox",usr);
tab.query();
if(tab.next()){
value.firstName = tab.getValue("first_name");
}
return JSON.stringify(value);
},

type: 'Autopopulate'
});
 
 
is this correct? Do i also need a client script?