GlideappRequestNew

sruthivarghese
Tera Contributor

Hi,

What does GlideappRequestNew do? I have a function which has the following code:

var req = new GlideappRequestNew();
var rc = req.copyCart(this.cartName, this.userID);
this.clearCart();
return rc;

As of what I understood, it creates an REQ. Please correct me if I am wrong. If it creates an REQ, it should map the requested for field to the cart's requested for field.

 

But for some reason the requested for in the REQ created does not show the correct value.

 

Can someone help me out in this?

 

Thanks,

Sruthi

11 REPLIES 11

Nikhil Dixit
Giga Expert

Hi Sruthi,

 

Please go through to following link. It would be helpful for you.

 

https://community.servicenow.com/community?id=community_question&sys_id=bc474f29db1cdbc01dcaf3231f961901

 

Please mark answer correct and helpful based on the response.

Regards,

Nikhil Dixit

|www.DxSherpa.com|

 

Surendra Raika1
Kilo Guru

Yeah its used to copy the Request ..

 

var req = new GlideappRequestNew();
var rc = req.copyCart('99798c894f6e130023df45dba310c7d9', gs.getUserID());
rc;

I hard- coded just to try it out its working fine ...  gs.getUserID() will set the Opened By ... 

Surendra Raika1
Kilo Guru

Can you post the xml of both the records.. please

Tim Grindlay
Kilo Sage

That's the placeOrder() function in the 'cart' script includes. 

 

To set the requested_for field on the request you can either create a before insert business rule on the sc_request table that grabs a variable value (what we currently do) or when you instantiate the cart use SPCart instead. You can then use SPCart.setRequestedFor() to set the requested for user. I'm currently looking at using this for our particular use case. 

Here's an example from what I did. Replace the text in the <> brackets with your code.

 

var callerID = <sys_id of your caller>;


var cartId = GlideGuid.generate(null); //Or any string


var cart = new SPCart(cartId,callerID);

 

var item = cart.addItem(<sys_id of your catalog item>);

 

cart.setVariable(item, <variable name>, <variable value>);

 

cart.setRequestedFor(callerID);

 

var SCrequest = cart.placeOrder();