Can you update Record Producer Variables from the submitted Record Fields

jonathangilbert
Kilo Sage

Hi All

 

We courrently have a record producer where variables are mapped to fields on the table. We have had to map the varaibles to fields so that we can trigger notifications and also aid in reporting ( reporting is slow and time consuming when accessign the variables directly.

 

The end user is able to access their submitted ticket in the Portal and update their responses on each of the variables, which in turn updates the field values on the record ( which is correct)

 

What I would like to be able to do is if the value of the field on the submitted record changes,  it then update the variable value to ben the same.

 

An example of the reasoning behind this is if a technician is veiwing mulitple tickets in list view, they could update multiple records in one go, which in turn would update the variable responses for each of those tickets. As it stands they would have to go into each ticket and update the variable in question.

 

I have tried with a the below business rule script, but it does not work:-

 

 

(function executeRule(current, previous /*null when async*/) {

producer.wh_location_of_where_accident_happened = current.location;


})(current, previous);
 
 
Does anyone know if this is possible to do or will require more automation usign Integration hub to look up and update the variable records
8 REPLIES 8

@jonathangilbert 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Morning Ankur,

Thansk for the revised code, but it is still not working as expected. If I change the value on the record, both mapped and unmapped variables update to "undefined". 

@jonathangilbert 

Did you add log and debug in that business rule?

without that you know where it's breaking

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

pavani_paluri
Giga Guru

Hi @jonathangilbert ,

 

Variables will be stored in sc_item_option_mtom table. Please use below script to update the variable.

 

(function executeRule(current, previous /*null when async*/) {

// Only run if the location field has changed
if (current.location != previous.location) {

// Get the variable definition by name
var variableName = 'wh_location_of_where_accident_happened'; // sys_name of the variable

var varDef = new GlideRecord('item_option_new');
varDef.addQuery('name', variableName);
varDef.addQuery('cat_item', current.cat_item); // Optional, to be precise
varDef.query();

if (varDef.next()) {
// Find the variable response record (option mtom)
var varValue = new GlideRecord('sc_item_option_mtom');
varValue.addQuery('request_item', current.sys_id);
varValue.addQuery('sc_item_option', varDef.sys_id);
varValue.query();

if (varValue.next()) {
varValue.value = current.location;
varValue.update();
}
}
}

})(current, previous);

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P