Create a request from an "UI action"

mustapharabat
Mega Expert

Hello all

I would like that when we click on the link "Creation of account"= >a request is created by applying the "catalog item" which is called "" Creation of account "

The sysId of this "catalog item" is "5ab22dd36fe39900a3e267712e3ee414"

I created this script

The request is creating well but not the RITM (request_item)!

find_real_file.png

Thank your four your help.

1 ACCEPTED SOLUTION

Hi David,



I try this script and it works well:



createServiceRequest();


function createServiceRequest() {


var cart = new Cart();


var item = cart.addItem('5ab22dd36fe39900a3e267712e3ee414');


cart.setVariable(item, 'short_description', "Request to create an account");


cart.setVariable (item,'User',current.sys_id);


cart.setVariable (item,'Location',current.location);


cart.setVariable (item,'login',current.user_name);




var cartGR = cart.getCart();


cartGR.requested_for = current.sys_id;


cartGR.update();




var newSerReq = cart.placeOrder();


newSerReq.update();




var disMessage = 'created request: ' + newSerReq.number;


gs.addInfoMessage(disMessage);


action.setRedirectURL(newSerReq);


action.setReturnURL(current);


}




function getRITM(serReq) {


var ritm = '';


var grRITM = new GlideRecord('sc_req_item');


grRITM.addQuery('request',serReq);


grRITM.query();


if(grRITM.next()) {


ritm = grRITM.sys_id;


}


return ritm;


}


View solution in original post

6 REPLIES 6

Hi David,



I try this script and it works well:



createServiceRequest();


function createServiceRequest() {


var cart = new Cart();


var item = cart.addItem('5ab22dd36fe39900a3e267712e3ee414');


cart.setVariable(item, 'short_description', "Request to create an account");


cart.setVariable (item,'User',current.sys_id);


cart.setVariable (item,'Location',current.location);


cart.setVariable (item,'login',current.user_name);




var cartGR = cart.getCart();


cartGR.requested_for = current.sys_id;


cartGR.update();




var newSerReq = cart.placeOrder();


newSerReq.update();




var disMessage = 'created request: ' + newSerReq.number;


gs.addInfoMessage(disMessage);


action.setRedirectURL(newSerReq);


action.setReturnURL(current);


}




function getRITM(serReq) {


var ritm = '';


var grRITM = new GlideRecord('sc_req_item');


grRITM.addQuery('request',serReq);


grRITM.query();


if(grRITM.next()) {


ritm = grRITM.sys_id;


}


return ritm;


}


Hello ,

I tried your script it works well on the form by creating REQ and RITM.

I want to implement the same on the Listview records , if the user selects the records and click on the UI button i would like to create an REQ. is this possible?