Copy the state choice value from one table to another table

Divya K1
Tera Guru

Hi All,

asmt_assessment_instance.state : State field is choice field with different languages.

requirement is copy the Display value of asmt_assessment_instance.state to asmt_assessment_instance_question. u_assessment_state.  The script probably needs to be run to update the values on the records in the asmt_assessment_instance_question table that have the State in non-English. State value should update with only english language choice value.

1 ACCEPTED SOLUTION

Hi Ankur,

 

Thanks for helping, the below script worked

when to run filter Conditions -- state changes

Advanced --condition - current.state != previous.state

 

var questionGR = new GlideRecord('asmt_assessment_instance_question');
        questionGR.addQuery('instance', current.sys_id);
        questionGR.query();

        while (questionGR.next()) {
            questionGR.u_assessment_state = current.getValue('state');
            questionGR.update();
        }

View solution in original post

22 REPLIES 22

@Divya K1 

you are copying display value, why not copy just the value?

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

Hi Ankur,

 

current business rule written on this table "asmt_assessment_instance" runs after update. Here is the script 

 

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

    var queGr = new GlideRecord('asmt_assessment_instance_question');
    queGr.addQuery('instance', current.sys_id);
    queGr.query();
    while (queGr.next()) {
        queGr.u_assessment_state = current.state.getDisplayValue();
        queGr.update();
    }
   
})(current, previous);

@Divya K1 

try to copy the value and not display value

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

    var queGr = new GlideRecord('asmt_assessment_instance_question');
    queGr.addQuery('instance', current.sys_id);
    queGr.query();
    while (queGr.next()) {
        queGr.u_assessment_state = current.state;
        queGr.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

Hi Ankur,

 

I will try and let you know

@Divya K1 

any update?

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