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

Hi Tim,

 

Unexpectedly i also had the same requirement and your above solution worked for me to set 'Requested for' field as required.

But i am facing issue in setting the 'Opened by' field in Request,as opened by field also taking the value of 'Requested for' field.

Can you please also suggest how can we set the opened by field value as the person who is submitting the request??

Hi, 

You should be able to just create a before create business rule on the request table to set the value. 

Tim

Tim Grindlay
Kilo Sage

I had to revisit this requirement and came across my post. I since found a simpler way to set the opened by user, it was right there all along. I also posted my solution here.

var cat_item = ""; //Sys ID of the catalogue item you're adding
var opened_by = ""; //Sys ID of your opened by user
var requested_for = ""; //Sys ID of the requested for user



var cartId = GlideGuid.generate(null); //Generate the sys ID for the cart
var cart = new SPCart(cartId, opened_by); //Create the cart with the opened_by user
var item = cart.addItem(cat_item); //Add the item to the cart

//Define your variables 
//cart.setVariable(item, <variable name>, <variable value>);

cart.setRequestedFor(requested_for);

var SCrequest = cart.placeOrder();

@ Tim Grindlay, Thanks for this code. I have 2 queries:

1. Can we call this from a BR

2. How to get catalog client script and UI policies triggered while a RITM is created from this code?

Hi Taniya, 

1. Yes you can call this from a business rule, but the script I posted is just the key parts of my solution. You will have to modify it for your purpose. For example, you could build it into a function that you call in a script includes so that you can re-use it elsewhere.

The use case I had was we have a custom generic 'issue' task type for our customers that can be turned into an incident or service request. I used this code to generate the service request from the issue, and control who the opened_by and requested_for users were.

2. This code is run on the server, whereas client scripts and UI policies are run on the client. You could use an Ajax call to the server to run the code, create a RITM and return data back into your client script or UI policy but... that sounds very messy and problematic. I recommend you post a new question on the community with the problem you're facing and the outcome you require. There could be a much easier way to achieve what you're trying to do.

Tim