IHow do you copy catalog variables to a request field?

kmathis
Kilo Contributor

I've seen this topic in the community a lot, but no straight answers on how to accomplish this.

I have two variables in a Service Catalog item that I need to copy to a field in the Request (sc_request).   Is this possible?   I've tried writing a Business Rule, a variable client script, etc.   I cannot copy these variables contents into a Request field.

Thanks in advance!

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Kari,



Write a Before Insert Business rule on sc_request table and add the following script in there. The following script copies all the questions and their values of all the requested items into description field on the request form



var gr= new GlideRecord("sc_req_item");


  gr.addQuery('request',current.sys_id);


  gr.query();


  var varArr='';


  while(gr.next()){


  var set = new GlideappVariablePoolQuestionSet();


  set.setRequestID(gr.sys_id);


  set.load();


  var vs = set.getFlatQuestions();


  for (var i=0; i < vs.size(); i++) {


  if(vs.get(i).getLabel() != '') {


  varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';


  }


  }


  }


  current.description=varArr;




Thanks,


Abhinay




PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

24 REPLIES 24

Abhinay Erra
Giga Sage

Kari,



Write a Before Insert Business rule on sc_request table and add the following script in there. The following script copies all the questions and their values of all the requested items into description field on the request form



var gr= new GlideRecord("sc_req_item");


  gr.addQuery('request',current.sys_id);


  gr.query();


  var varArr='';


  while(gr.next()){


  var set = new GlideappVariablePoolQuestionSet();


  set.setRequestID(gr.sys_id);


  set.load();


  var vs = set.getFlatQuestions();


  for (var i=0; i < vs.size(); i++) {


  if(vs.get(i).getLabel() != '') {


  varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';


  }


  }


  }


  current.description=varArr;




Thanks,


Abhinay




PS: Hit like, Helpful or Correct depending on the impact of the response


Thanks so much!   This works great!



I would like to clean it up just a bit and place the Request_title variable into the short_description field of the Request.


Hi Abhinay,



Can you please help me out on this?


I need to populate the Requested For on req table in "requested_for" fiedl and for that I tried your code but it is not working.



(function executeRule(current, previous /*null when async*/) {




var gr= new GlideRecord("sc_req_item");


  gr.addQuery('cat_item','cd293c87dbc90f806a93f2b6af961911');


  gr.addQuery('request',current.sys_id);


  gr.query();


  var varArr='';


  while(gr.next()){


  var set = new GlideappVariablePoolQuestionSet();


  set.setRequestID(gr.sys_id);


  set.load();


  var vs = set.getFlatQuestions();


  for (var i=0; i < vs.size(); i++) {


  if(vs.get(i).getLabel() != '') {


  varArr+=vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue()+'\n';


  }


  }


  }


  current.requested_for = gr.variables.WD_sa_requested_for;


 


})(current, previous);


Just double checking the requirements Sreeja... is that all you want to do is copy the RITM variable value to the request's requested_for field?



What table is your BR running on?


Hi Chuck,


My requirement is to copy a particular variable value from RTIM to Request table. The name of the variable is "WD_sa_requested_for" and I need this to be on "requested_for" field in sc_request table.


The BR is running in sc_request table



Regards,


Sreeja