logo

NJP

Set Order guide name on your Request table

Import · Dec 24, 2018 · article

Some time requirement come up to set Order Guide name on Request [sc_request] table. So that user can see a report based on order guide to implement it we need to follow this.

When user submit request before checkout system using two table to store information.

  1. Shopping Cart [sc_cart]: Information about user cart.

image

2. Item [sc_cart_item]: Information about Items. If we open item, we will see system also have information about “Order Guide”

image

To implement it you need to do following

  1. create a custom field Order Guide (u_order_guide) on “sc_request” table.
  2. Write a before Insert business rule on Request (sc_request) table

Now check on Advanced option and write following code

var gr = new GlideRecord("sc_cart");
gr.get("user", gs.getUserID());

var gr = new GlideRecord("sc_cart");
gr.addQuery("user", gs.getUserID());
gr.query();
while(gr.next()){
  //gs.print(gr.name);
  if(gr.name == "DEFAULT"){
    var grcart = new GlideRecord("sc_cart_item");
        grcart.addQuery('cart',gr.sys_id);
        grcart.query();
        while(grcart.next()){
           if(grcart.order_guide != ""){
             current.u_order_guide = grcart.order_guide;  
           }    
        } 
  }
}

You can modify this code as per your need.

View original source

https://www.servicenow.com/community/itsm-articles/set-order-guide-name-on-your-request-table/ta-p/2316778