Showing changes to variables in SC Items in the Activity register

nmcl
Giga Expert

Hi, I can see the audit history for variables within service catalog items, however I want to show any changes within 'activity'.

I've tried adding all available fields within 'personalize activities' but this does not capture any changes to the variables.

 

Has anyone else managed to do this?

19 REPLIES 19

Thanks a lot for this Doug, look forward to v3!



Cheers,


Daniel


I have a lot to fill out on this form.. but if someone needs this working in their system.. this is the code i have so far.. i am breaking each type of variable into a case system on a switch.. so if it doesn't work on a variable type <for example reference variables> replace the code i have in that variable type with the appropriate code....


i am filling in the other types as i go.



______________________________________________________


    if (previous.value != current.value){


            var var_owner = new GlideRecord('sc_item_option_mtom');


            var_owner.addQuery('sc_item_option',current.sys_id);


            var_owner.query();


            if (var_owner.next()){


                    var itm = new GlideRecord('sc_req_item');


                    itm.addQuery('sys_id', var_owner.request_item);


                    itm.query();


                    if (itm.next()){


                          itm.comments = 'Variable updated ' +   current.item_option_new.getDisplayValue() + ' value changed from ' + getValues(previous.value,current.item_option_new) + ' to ' + getValues(current.value,current.item_option_new) + ' By ' + gs.getUserName();


//itm.description = 'test';


                          itm.update();


                  }        


            }


    }


function getValues(q_value,q_sid){


  var answer = '';


    var q_type = new GlideRecord('question');


    q_type.addQuery('sys_id', q_sid);


    q_type.query();


    while(q_type.next()){


    switch(q_type.type.toString()){



            case('5'):   // Select box


                                              var qc = new GlideRecord('question_choice');


                                              qc.addQuery('question',q_sid);


                                              qc.addQuery('value',q_value);


                                              qc.query();


                                              if (qc.next()){


                                                            answer = qc.text;


                                              }


              break;


              case('14'): //macro


                            answer = "Macro was changed";


                break;


                case ('15'):   //UI Page


                          answer = "UI Page was changed";


                break;


              case('18'):   //lookup select box   investigate this.


                                answer = q_value;


              break;


              case('21'): //list collectior investigate this


                                  answer = q_value;


              break;


              case ('22'): // lookup multiple choice   investigate this


                                answer = q_value;


              break;


              case('23'): //html


                                answer = "HTML was changed";


              break;


              case('3'): //Multiple choice


                                              qc = new GlideRecord('question_choice');


                                              qc.addQuery('question',q_sid);


                                              qc.addQuery('value',q_value);


                                              qc.query();


                                              if (qc.next()){


                                                            answer = qc.text;


                                              }


              break;


              case('4'): //numeric scale investigate this


                              answer = q_value;


              break;


              case('8'): //reference   investigate this


                              answer = q_value;


              break;


                  default:


                          answer =   q_value;


            break;


  }


  if (answer == ''){answer = 'Null';}


  return answer;


}


}


Doug Andrews happen to use it for one of my colleague today ... But what about reference fields? these are giving sys_id's .. Any work around for this ?


I haven't had time to mess with that one yet.. was told for our purposes sid is fine <we can look it up if needed>



i suspect to make it work you will need to look up the question and grab the table the reference variable is based on <q_sid inside the function> then look up the q_sid on that table.. and grab it's display value... but haven't had time to work out the code for doing so yet...



the code for list collectors will be very similar.. just load the value into an array and thumb through the same process once per answer.



to make it work you need to modify case 8



              case('8'): //reference   investigate this


                              answer = q_value;   //replace this with code that works.


              break


will try that ... Will post a update if I happen to crack this one Thanks !