Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function executeRule(current, previous /*null when async*/) {
- //part 1, for variables with sys_user reference we need user_name instead of display value
- var answer = '';
- var refArr = [];
- var gr = new GlideRecord('sc_item_option_mtom');
- gr.addQuery('request_item', current.getUniqueValue());
- 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');
- //only sys_user reference variables which are not empty
- gr.query();
- while(gr.next()){
- refArr.push(gr.sc_item_option.item_option_new.getDisplayValue()); //push variable names for later use in part 2
- var arrayList = gr.sc_item_option.value.split(","); //push comma separated values into an array
- var arrayListLength = arrayList.length;
- var userNames = '';
- var names = '';
- for (var j=0; j<arrayListLength; j++) {
- var user = new GlideRecord('sys_user');
- user.get(arrayList[j]);
- if((j + 1) == (arrayListLength)){ //if there is only 1 element in array we don't need a comma separator
- names += user.name; //get name of user
- userNames += user.user_name; //get username of user
- }
- else{
- names += user.name + '; '; //get name of user
- userNames += user.user_name + '; '; //get username of user
- }
- }
- answer += gr.sc_item_option.item_option_new.getDisplayValue() + ' (name) = ' + names + '\n';
- answer += gr.sc_item_option.item_option_new.getDisplayValue() + ' (user id) = ' + userNames + '\n';
- }
- //part 2, get all other variable labels and their display values
- var varLabel;
- var varValue;
- var arrUtil = new ArrayUtil();
- var set = new GlideappVariablePoolQuestionSet();
- set.setRequestID(current.getUniqueValue()); set.load();
- var vs = set.getFlatQuestions();
- for (var i=0; i < vs.size(); i++){
- varLabel = vs.get(i).getLabel(); //get label of variable
- varValue = vs.get(i).getDisplayValue(); //get display value of variable
- 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
- answer +=(varLabel + " = " + varValue + "\n");
- }
- }
- current.u_summary = answer;
- current.update();
- })(current, previous);
Advertisement
Add Comment
Please, Sign In to add comment