Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ServiceDesk Call create generic request

williame
Tera Contributor

So I am new to the Service Desk Call option,

I was able to get the Incident information the way I want,   now I wanted to create a General Request item - I have tried using the format of

New call to create generic request`

However it just isnt copying any of my data from the NewCall to the request/item and not actually submitting the request.

Would anyone be willing to share their experiences/code?

basically i want to take

short_description to task short description

description to task description

caller to task requested for

assignment group to task assignment group

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI William,



Check this out:


Service catalog script API



createServiceRequest();




function createServiceRequest() {


var cart = new Cart();


var item = cart.addItem('af695d47314610003e55ce5fcb8deb06');



cart.setVariable(item, 'short_description', current.short_description);


cart.setVariable(item, 'description', current.description);


cart.setVariable(item, 'sr_cmdb_ci', current.cmdb_ci);


cart.setVariable(item, 'sr_resolver_group', current.assignment_group);



var cartGR = cart.getCart();  


cartGR.requested_for = current.u_affected_person;


cartGR.update();  


var newSerReq = cart.placeOrder();


newSerReq.opened_by = current.caller_id;


newSerReq.update();




var activityLogMsg = 'Your Incident ' + current.number + ' has been cancelled and a Service Request ' + newSerReq.number + ' is created. No action is needed on your part';


current.state = 5;


current.active = false;


current.work_notes = activityLogMsg;


current.parent = getRITM(newSerReq.sys_id);


current.update();



var disMessage = 'Incident ' + current.number + ' has been cancelled and your work will be captured via the newly created Service 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;


}




Regards,


View solution in original post

20 REPLIES 20

I created a new business rule as below to create the Request / item / task , I believe because of this I am not able to use / utilize the oob rule to link it back or don't see the BR for it.



var generalRequestSysID = '08eb99250feb0200462df3f692050e47';




// Create the cart using the Cart API. NOTE: THIS WILL CLEAR ANY ITEMS IN THE USER'S CART!!!!


var cart = new Cart();


var item = cart.addItem(generalRequestSysID);


cart.setVariable(item, 'inhibit_workflow', 'skip');


// update the form variables


cart.setVariable(item, 'requested_for', current.caller_id);


// use the reported by user as the requested by if available


if (JSUtil.notNil(current.u_user)) {


cart.setVariable(item, 'requested_by', current.u_user);


} else {


cart.setVariable(item, 'requested_by', current.u_user);


}


cart.setVariable(item, 'converted_incident', current.sys_id); // case number


cart.setVariable(item, 'opened_by', current.u_user); // opened by /requested_by


cart.setVariable(item, 'category', 'other');


cart.setVariable(item, 'phone', current.u_phone_number); // phone number


cart.setVariable(item, 'email_address', current.caller.email); // Affected User Email


cart.setVariable(item, 'location_building', current.u_building);


cart.setVariable(item, 'location_area', current.u_area);


cart.setVariable(item, 'location_area_not_available', current.u_area_not_available);


cart.setVariable(item, 'enter_location', current.u_area_text);


cart.setVariable(item, 'description', current.short_description + '\n\n' + current.description);


cart.setVariable(item, 'pc_id', current.u_pcid);


cart.setVariable(item, 'assignment_group', current.u_assignment_group);


cart.setVariable(item, 'requested_for', current.caller);


cart.setVariable(item, 'comments', "Case converted from " + current.number + "\nPCID: " + current.u_pcid.name );


cart.setVariable(item, 'work_notes', "Case converted from " + current.number + "\nPCID: " + current.u_pcid.name );


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


cart.setVariable(item, 'call_number', current.number);


var cartGR = cart.getCart();


cartGR.requested_for = current.caller;


cartGR.update();




var req = cart.placeOrder();



var reqSysID = req.sys_id;


req.short_description = current.short_description;


req.description = current.description + '\n\n + Case converted from ' + current.number;


req.comments = current.description;


req.u_pcid = current.u.pcid;


req.requested_for = current.caller; // Affected User


req.opened_by = gs.getUserID();


req.u_requested_by = current.opened_by;


req.u_transferred = current.sys_id;


req.stage = 'requested';


req.update();



var ritm = '';


var gRitm = new GlideRecord('sc_req_item');


gRitm.addQuery('request', req.sys_id);


gRitm.query();


if (gRitm.next()) {


gRitm.short_description = current.short_description;


gRitm.description = current.description + '\n\n' + "Case converted from " + current.number + "\nPCID: " + current.u_pcid.name ;


gRitm.requested_for = current.caller; // Affected User


gRitm.opened_by = gs.getUserID();


// use the reported by user as the requested by if available


if (JSUtil.notNil(current.u_user)) {


gRitm.u_requested_by = current.u_user;


} else {


gRitm.u_requested_by = current.opened_by;


}


gRitm.approval = 'approved';


gRitm.stage = 'fulfillment';


gRitm.update();


ritm = gRitm;


}



// Create the TASK


var task = new GlideRecord("sc_task");


task.initialize();


task.request = req.sys_id;


task.request_item = ritm.sys_id;


task.u_item = ritm.cat_item;


task.opened_by = ritm.opened_by;


task.u_requested_for = current.caller;


task.short_description = ritm.short_description;


task.description = ritm.short_description + "\n\n" + ritm.description;


task.cmdb_ci = current.u_config_item;


task.assignment_group = current.u_assignment_group;


task.assigned_to = current.u_assigned_to;


task.u_call = current.number;


task.work_notes = "Reported By: " + current.u_user.name + "\n\n" + "Affected User: " + current.caller.name + "\n\n" + "Affected User Phone: " +   current.u_phone_number;


task.work_notes = "Current Short Description: " + current.short_description + "\n\n" + "Current Description: " + "\n\n" + current.description;


task.work_notes = "Current PCID: " + current.u_pcid.name;


task.work_notes = "Current Assignment Group: " + current.u_assignment_group.name;




var taskSysID = task.insert();




// copy the Incident attachments to the TASK


GlideSysAttachment.copy("new_call", current.sys_id, 'sc_task', taskSysID);



// show the TASK form


gs.addInfoMessage("We are now tracking Case " + current.number + " as a Request. Please refer to   " + req.number + " .");


action.setRedirectURL(task);


action.setReturnURL('new_call_list.do?sysparm_query=active%3Dtrue');


HI Will,



Are you able to trigger this or not?



Let me know if any issue.



Regards,


I am not able to trigger the Link back to call


On Call Do you want to set some fields or what.. sry I got confused.



Please clarify.



Thanks


I need to be able to trigger the OOB rule "Link back to the call that generated it" that is under the Request Business rules - currently it has a condition for when it gets triggered and since I created a new rule I don't seem to be able to trigger it.