The CreatorCon Call for Content is officially open! Get started here.

Set Record history in Custom Table

tanz
Tera Expert

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.

1 REPLY 1

Sai Kumar B
Mega Sage

@tanz 

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;
}