How to get old value in Business rules

Kentaro Numata
Tera Guru

Hi, It's Ken.

I want to get the Old Value of the Reference column.
But I can't get it using Previous.

Is there a better way?

 

Thanks,

Kentaro.

 

---

gs.addInfoMessage("current.group:"+ current.group);
gs.addInfoMessage("previous.group:"+ previous.group);
gs.addInfoMessage("current.comments:"+ current.comments);
gs.addInfoMessage("previous.comments:"+ previous.comments);

 

 

スクリーンショット 2023-02-17 15.09.33.png

1 ACCEPTED SOLUTION

Sai Shravan
Mega Sage

Hi @Kentaro Numata ,

 

If the current.group field is returning undefined, it's possible that the field does not exist on the table you are currently working with. Double-check the table schema and ensure that the group field is present.

 

If you're working with a GlideRecord object, make sure that you have called the query() method to retrieve a record before attempting to access its fields. Here's an example of how to use a GlideRecord to retrieve the group field:

You can give a try using background script

var gr = new GlideRecord('incident'); // You table name
gr.addQuery('number', 'INC0010001'); // Replace with the appropriate query criteria
gr.query();
if (gr.next()) {
gs.log("current.group:" + gr.getValue('group'));
}

 

Here getValue returns the sys_id of the group, you can replace with getDisplayValue.

 

Regards,
Shravan.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

3 REPLIES 3

Sai Shravan
Mega Sage

Hi @Kentaro Numata ,

 

If the current.group field is returning undefined, it's possible that the field does not exist on the table you are currently working with. Double-check the table schema and ensure that the group field is present.

 

If you're working with a GlideRecord object, make sure that you have called the query() method to retrieve a record before attempting to access its fields. Here's an example of how to use a GlideRecord to retrieve the group field:

You can give a try using background script

var gr = new GlideRecord('incident'); // You table name
gr.addQuery('number', 'INC0010001'); // Replace with the appropriate query criteria
gr.query();
if (gr.next()) {
gs.log("current.group:" + gr.getValue('group'));
}

 

Here getValue returns the sys_id of the group, you can replace with getDisplayValue.

 

Regards,
Shravan.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Thank you! I just resolved!

Pavankumar_1
Mega Patron

Hi @Kentaro Numata ,

Refer below script and current.referencefield will give sysid we can get user id or other values like below

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

    gs.addInfoMessage(current.u_customer.user_name);//give current record user name
    gs.addInfoMessage(previous.u_customer);//give your reference name it will give older reference sysid
    gs.addInfoMessage("Comments is 1 " + current.comments.getJournalEntry(1));//it will give latest comment

})(current, previous);

 Screenshot (673).png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar