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

Dubz
Mega Sage

Hi Mustapha,



You haven't created an RITM record so there is nothing there to dot-walk to. You'll need to add another glide record to the sc_req_item table and create a record there and link it back to your new request.


Also, you should use initialize() when creating new records, it creates an empty record that can then be populated with info.



var demande = new GlideRecord('sc_request');


demande.initialize();


demande.short_description = .....etc etc etc


thank you David for your reply.




But how to link it back this RITM to the created request.


I add the following script but the ritm does not appear in the "requested items":


var grRITM = new GlideRecord('sc_req_item');


grRITM.initialize();


grRITM.cat_item= "5ab22dd36fe39900a3e267712e3ee414";


grRITM.request = demande;


grRITM.insert();


Hi Mustapha,



Change it as below, demande is just a glide record object it will return undefined.



grRITM.request = demande.sys_id;