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

sahiltelani
Tera Contributor

Hi @Divya K1,

 

Can you confirm if the u_assessment_state field is a choice type or string type? 

 

If it's a custom choice field, it is going to take the value as per users language.

 

Let me know.

 

Hi Sahil,

 

u_assessment_state field is a string type

Hello,

So ultimately, whenever the user from other user language will be making any changes then it takes the display value. Did the script shared by Ankur work?

I guess it wont. Here you'll have to additionally glide in sys_choice table and query it to "English" type choices and then populate the field. 

Lemme know if you need help in writing the script. Also, mark my answer as Helpful if it solved your issue.

 

Regards,

Sahil

@sahiltelani 

the latest script I shared is about performing GlideRecord on sys_choice

I am awaiting feedback from @Divya K1 

Hopefully it should work

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

Hi Ankur,

I tried with your suggestion by keeping logs as well.. Still u_assessment_state field is updating based on WOT assigned to user language. i checked the logs, i can see the warnings, please find the screenshots 

 

var queGr = new GlideRecord('asmt_assessment_instance_question');
    queGr.addQuery('instance', current.sys_id);
    queGr.query();
    while (queGr.next()) {
        var gr = new GlideRecord("sys_choice");
        gr.addEncodedQuery("nameSTARTSWITHasmt_assessment_instance^element=state^languageSTARTSWITHen^valueSTARTSWITH" + current.state);
        gr.query();
        if (gr.next()) {
            queGr.u_assessment_state = gr.label;
            queGr.update();

        }
    }