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.

Sanjeev Kumar1
Kilo Sage

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.

         find_real_file.png

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

find_real_file.png

 

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.

Version history
Last update:
‎12-24-2018 05:14 AM
Updated by: