Requested For field is defaulting to logged in user in Service Request

Luke Dibben1
Kilo Contributor

Hi all,

We are building our Service Catalog but when we submit a request, the 'Requested for' field on the Request defaults to the persons name who logged the request. We would like to be able to submit requests on behalf of others. We created a Variable Called "Service Recipients Name". This Variable is in a Variable Set called "Common Requested For". We would like to copy its value automatically to the "Requested For" field. (See below) Any ideas?

ServiceNow - catalog item.png

Thanks,

Luke

4 REPLIES 4

Vidyasagar Anku
Kilo Contributor

Hi Luke,



Write onSubmit client script on Variable Set:


function onSubmit() {


  var reqFor = g_form.getValue('requested_for'); //Your "Common Requested For" variable goes here



  var ga = new GlideAjax('<script>'); // Script include to update the cart and set the Requested for


  ga.addParam('sysparm_name','populateRequestedFor'); //Script include function


  ga.addParam('sysparm_requested_for',reqFor);


  ga.getXMLWait();


}



Script include function would be:


populateRequestedFor: function(){


  var req_for = this.getParameter('sysparm_requested_for');


  var gr = new GlideRecord('sc_cart');


  gr.addQuery('user', gs.getUserID());


  gr.query();


  if(gr.next()){


  gr.requested_for = req_for;


  gr.update();


  }


},



Best Regards,


Vidyasagar A.


Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,



Do you have a parent request for this RITM?



And you want to copy requested for which should be same as variables set field what you mentioned, rite?


Mihir Mohanta
Kilo Sage

Thanks Mihir, this fixed the issue!



Luke