Set Record history in Custom Table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 02:50 AM
I have created 3 choices in INC table A, B, C. I have also created a customised table(u_choices_history) table which will display the choices and I am pulling the value from INC table using an before insert/update BR and creating the record in my custom table . However I want to also get the history of the choices against the INC number and the choices updated on.
Sample table
u_choices_history
INC Number Choice Value Choice History
INC001 A A
INC001 B B A
INC001 C C B A
INC002 A A
INC002 B B A
INC003 A A
Please let me know how I can achieve the table scenario to get the choice history.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 03:36 AM
You have to Glide sys_audit table to fetch choice history value
Below is the sample code that fetches the choice old and new value for the incident record, Modify the encoded query accordingly
var fetchChoiceValues = new GlideRecord('sys_audit');
fetchChoiceValues.addEncodedQuery('tablename=incident^fieldname=choice_field_name^documentkey=INC_record_sys_id');
fetchChoiceValues.query();
if(fetchChoiceValues.next()) {
//var choiceOldValue = fetchChoiceValues.oldvalue;
//var choiceNewValue = fetchChoiceValues.newvalue;
}