Fix script giving an unexpected result

1_DipikaD
Kilo Sage

Hi All,

Before I had run the following script on alphabet field where the requirement was when I select others in alphabet field the existing value should populate on other alphabet field.

 

var grTable = new GlideRecord('table_name');
grTable.addEncodedQuery('filter');//use the filter in list view and copy the query.
grTable.query();
while (grTable.next()) {
    if (grTable.caste_field) {
        grTable.other_caste = grTable.caste_field;
        grTable.update();
    }
}

1_DipikaD_0-1728886616001.png

 

 

It was working fine but few days back I notice  the mentioned fields are full of with value as others instead of the existing value. Till now I am not able to find out how it is happened .

 

Is it possible to get previous record as it was before or any other solution to get the expected result ?

 

For more info also refer to  :-  Solved: populate exiting data in other field and keep cast... - ServiceNow Community

 

Thank YOU

 

 

5 REPLIES 5

Harsh_Deep
Giga Sage
Giga Sage

Hello @1_DipikaD 

 

I also faced same issue and I used getValue()

 

var grTable = new GlideRecord('table_name');
grTable.addEncodedQuery('filter');//use the filter in list view and copy the query.
grTable.query();
while (grTable.next()) {
    if (grTable.caste_field) {
        grTable.other_caste = grTable.getValue('caste_field');
        grTable.update();
    }
}

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Will it get previous record as it was before ?

Eshwar Reddy
Kilo Sage

Hi @1_DipikaD 
--> To get previous record as it was before

 

If it was achieved using a background script.
Yes, it is possible.

Go to the left navigator and search for "Script Execution History."
Find the relevant entry.

In the Related Links, click Rollback Script Execution.

-->


you can use getValue() or toString()
Thanks 
Eshwar

I had tried to rollback but they are got expired . Also I tried above methods still haven't get any result . I don't have backup as well . It's working fine on QA and UAT but in DEV it's not working as expected. Is there any possibility in upcoming days in QA and UAT also it will behave like DEV ?