tommeh_1337

Copy RITM variables to summary

Mar 15th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function executeRule(current, previous /*null when async*/) {
  2.    
  3.     //part 1, for variables with sys_user reference we need user_name instead of display value
  4.     var answer = '';
  5.     var refArr = [];
  6.     var gr = new GlideRecord('sc_item_option_mtom');
  7.     gr.addQuery('request_item', current.getUniqueValue());
  8. gr.addEncodedQuery('sc_item_option.item_option_new.reference=sys_user^ORsc_item_option.item_option_new.choice_table=sys_user^ORsc_item_option.item_option_new.list_table=sys_user^sc_item_option.valueISNOTEMPTY^ORDERBYsc_item_option.item_option_new.order');
  9.     //only sys_user reference variables which are not empty
  10.     gr.query();
  11.     while(gr.next()){
  12.         refArr.push(gr.sc_item_option.item_option_new.getDisplayValue()); //push variable names for later use in part 2
  13.         var arrayList = gr.sc_item_option.value.split(","); //push comma separated values into an array
  14.         var arrayListLength = arrayList.length;
  15.         var userNames = '';
  16.         var names = '';
  17.         for (var j=0; j<arrayListLength; j++) {
  18.             var user = new GlideRecord('sys_user');
  19.             user.get(arrayList[j]);
  20.             if((j + 1) == (arrayListLength)){ //if there is only 1 element in array we don't need a comma separator
  21.                 names += user.name; //get name of user
  22.                 userNames += user.user_name; //get username of user
  23.             }
  24.             else{
  25.                 names +=  user.name + '; '; //get name of user
  26.                 userNames += user.user_name + '; '; //get username of user
  27.             }
  28.         }
  29.         answer += gr.sc_item_option.item_option_new.getDisplayValue() + ' (name) = ' + names + '\n';
  30.         answer += gr.sc_item_option.item_option_new.getDisplayValue() + ' (user id) = ' + userNames + '\n';
  31.     }
  32.    
  33.     //part 2, get all other variable labels and their display values
  34.     var varLabel;
  35.     var varValue;
  36.     var arrUtil = new ArrayUtil();
  37.     var set = new GlideappVariablePoolQuestionSet();
  38.     set.setRequestID(current.getUniqueValue()); set.load();
  39.     var vs = set.getFlatQuestions();
  40.     for (var i=0; i < vs.size(); i++){
  41.         varLabel = vs.get(i).getLabel(); //get label of variable
  42.         varValue = vs.get(i).getDisplayValue(); //get display value of variable
  43.         if(varValue != '' && varValue != 'false' && varLabel != null && arrUtil.indexOf(refArr, varLabel) < 0){ //value is not empty, false or null and label of variable is not in refArr array to prevent duplicates
  44.             answer +=(varLabel + " = " + varValue + "\n");
  45.         }
  46.     }
  47.    
  48.     current.u_summary = answer;
  49.     current.update();
  50.    
  51. })(current, previous);
Advertisement
Add Comment
Please, Sign In to add comment