New Call / Ticket Table/ UI Action Script Help.

casey_barela1
Kilo Expert

I am implementing a New Call / Ticket Table UI action that will route tickets to either a Incident or Service Request. I have set up the form and it is working perfectly with Incidents however i am not able to make it translate to our environments service catalog ordering process because most of the items are blank currently and we are still in the process of building them. If you look at the code below it shows the two trees one for Incidents that is working perfectly and the other for Request.

 

What i am asking is can someone help show me what the code should look like if we bypassed the catalog and just created a requested item (record) with all the variables filled out directly in their like it has been for the incidents. Can this be done? This will be used just for our service desk and it will be very helpful to bypass the catalog and just make a REQ that can be empty then and RITM that has the data filled in so that the workflow can be started after saving.

 

Thanks in advance. This community Rocks.

 

The Code in green is for the Incident branch and i think could be copied for the Request Side. The Code in the red us what i want to replace and bypass the shopping cart and go straight to creating the RITM Record with the information like what was done for the incident.

 

var reqItem = current.u_request_item;

var requestedFor = current.u_requested_for;

var location = current.location;

var comments = encodeURI(current.comments);

 

if(current.u_call_type == 'Incident'){

    //Create a new incident record and redirect to the new incident

    var rec = new GlideRecord('incident');

    rec.initialize();

    rec.caller_id = requestedFor;

    rec.location = location;

    rec.short_description = current.short_description;

    rec.u_floor_area_room = current.u_floor_area_room

    rec.u_template = current.u_template;

    rec.description = current.description;

    rec.work_notes = current.work_notes;

    rec.comments = current.comments;

    rec.insert();

    action.setReturnURL('new_call.do');

    action.setRedirectURL(rec);

}

if(current.u_call_type == 'Request'){

    //Build the url and route the user to the request item

  var url = '';

  if(current.u_request_item.sys_class_name == 'sc_cat_item_guide'){

  url = 'com.glideapp.servicecatalog_cat_item_guide_view.do?sysparm_initial=true&sysparm_guide=' + reqItem + '&sysparm_user=' + //requestedFor + '&sysparm_location=' + location + '&sysparm_comments=' + comments;

    }

  else{

          url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' + requestedFor   + '&sysparm_location=' + location + '&sysparm_comments=' + comments;

    }

    action.setReturnURL('new_call.do');

    action.setRedirectURL(url);

}

 

function getCart(user){

    var cart = new GlideRecord('sc_cart');

    var userid = requestedFor;

  cart.addQuery('user', userid);

    cart.query();

    if(cart.next()){

          //We already have a cart so override the requested for value and empty it

          cart.requested_for = user;

          cart.update();

          var cartItems = new GlideRecord('sc_cart_item');

          cartItems.addQuery('cart', cart.sys_id);

        cartItems.deleteMultiple();

    }

    else{

          cart.initialize();

          cart.user = userid;

          cart.requested_for = user;

        cart.insert();

    }

  return cart;

}

current.state = 3;

current.update();

// 42 var userid = gs.getUserID();

 

Code was originally pulled from Creating the 'Call' (or 'Interaction') model in ServiceNow - YouTube

8 REPLIES 8

jshatney
Mega Expert

You need to look at the script include labeled "Cart".
It has all of the functions to programmatically create items in a script.



You technically cannot bypass the shopping cart, but this script include will help you add items to your cart and checkout.


Thanks, But did you forget to attach the script?


No. I was referring to a "Script Include" that is called "Cart"


danielbilling
Kilo Guru