- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 10:14 PM
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);
↓
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:12 PM
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.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:12 PM
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.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 12:28 AM
Thank you! I just resolved!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 11:16 PM
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);
ServiceNow Community MVP 2024.
Thanks,
Pavankumar