Order Guide - Requested for

sylvain_hauser
Tera Contributor

I would like to ask in the first step of an order guide the "requested for" user.

I tried to create the following variable:
- name: requested_for
- type: Reference
- Reference: sys_user
- mandatory
(Cascade Variables is ON)

But when you check out, the "Requested for:" field is still the curent user name...

Any idea?

Thanks!

8 REPLIES 8

rburgering
Kilo Contributor

Hi Sylvain,

The Requested_for is set on the 'cart' and is normally only controlled via the 'requested_for' widget on the front page of the catalog. This does make sense: you either order for yourself or for someone else, never combined.

To cut a long story short:
We use a global client script / global script to set the requested_for on the cart when selecting it in a field you just described. The code is below.



function onChange(control, oldValue, newValue, isLoading) {

if(oldValue != newValue){
var uid = AJAXEvaluateSynchronously("gs.getUserID()");
var rf = g_form.getValue('requested_for');
//alert('rf = ' + rf + ' uid = ' + uid);
var script = "setReqFor('" + uid + "','" + rf + "')";
var answer = AJAXEvaluateSynchronously(script);
}
}



function setReqFor(uid, rf) {

//gs.addInfoMessage('UID is ' + uid + ' RF is ' + rf);
var answer = false;
var rfr = new GlideRecord('sc_cart');
rfr.addQuery('name', 'DEFAULT');
rfr.addQuery('user',uid);
rfr.query();
if(rfr.next()){
rfr.requested_for = rf;
rfr.update();
answer = true;
}
return answer;
}


Good Luck!


Yes! That is exactly what I was looking for. It works perfectly:D


Hi, I am trying to use this example to do the same thing. I have a Catalog Item and I ask who the request is for. The variable is global and I named it requested_for. However, when I complete the request the requested_for is still set to the person currently logged in. Question... the global script is on what table?

I have it onChange- sc_cart - requested_for.

Thanks-Michele


I am still struggling with this.   I don't quite understand what to attach the onChange code to.



In this thread, people are suggesting that I attach it to the order guide table [sc_cat_item_guide] for the onchange of the "requested_for" field.


But there is no field named "requested_for" in the order guide table....