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

Ankur Bawiskar
Tera Patron
Tera Patron

@jonathangilbert 

you can use this syntax in after update business rule to update the variable value.

// query question_answer  table with your record sysId against Table sys ID field and then update the Value column with the field value

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

    // Add your code here
    var gr = new GlideRecord("question_answer");
    gr.addQuery("table_sys_id", current.sys_id);
    gr.query();
    while (gr.next()) {
        var mapField = question.field.toString(); // get the field name
        gr.value = current[mapField]; // update the variable value by updating the value column
        gr.update();
    }

})(current, previous);

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

Thanks for the reply Ankur, but nothing happens when it executes

@jonathangilbert 

Did you add log and see if it ran?

any error?

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

WELCOME

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

@jonathangilbert 

this is the updated code, I had a small mistake in above one, use this updated line

        var mapField = gr.question.field.toString(); // get the field name

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