Does anyone know how to access the order guide variables from the order guide script field?

johnnysharp
Tera Contributor

I would like to be able to access an order guide variable to use for a loop in the order guide script field. Does anyone know of a way to access the order guide variables within the order guide script field?

I have tried:

current.vars.<variable_name>

current.variables.<variable_name>

current.variable_pool.<variable_name>

guide.vars.<variable_name>

guide.variables.<variable_name>

guide.variable_pool.<variable_name>

11 REPLIES 11

l_g_1
Kilo Contributor

I spent hours looking for the solution on wiki and community. No one seems know any. Here is my dirty way of doing it. I hope this will save some time for next person looking for it.



var ans = g_request.getParameter('IO:c7894503db600300f83b7bedbf961977');



g_request allows you to tap directly into HTTP request to access form data (hence any variable). This is not really documented anywhere, but here is the API: RequestFacade (Apache Tomcat 6.0.53 API Documentation)



Of course you need use proper name   for parameter / variable. That will be IO:<sys_id_of_the_variable>. You can get it from the record or by inspecting page source.


Hi Leszek,



thanks to your hint with the g_request, I managed it to access the variables from the Order guide script field in a dynamic way.


I needed this due to the fact that we need an additional check for the entitlement of the items added by the Rule base, because not every item shall be displayed to every user.



Here is the script, that would check the entitlement and remove the item from the Order guide.


Maybe it helps someone:



var guide_sys_id = g_request.getParameter('sysparm_guide');  



//access the Rule bases in order to get the catalog items


var gr = new GlideRecord('sc_cat_item_guide_items');


gr.addQuery('guide', guide_sys_id);


gr.query();


while(gr.next()){


      var item_sys_id = gr.getValue('item');


      if(!GlideappCatalogItem.get(item_sys_id).canView()){


              guide.remove(item_sys_id);


              //gs.log(item_sys_id + ' removed due to entitlement');


      }


}



Regards,


Bastian


peter_repan
Tera Guru

g_request is not working in Service Portal 😞

Was anyone successful to get variable value in script when the Order guide is used in Service Portal?

Did you figure this out? Do we know if g_request is officially not supported in SP?

Hi Peter,

Poping late in the thread but had the same issue that I could solve.

If you need to access order guides variables in the related items without needing to map them on all (in my case to evaluate which default value has to be set on an child item variable), I instanciated a "copy" of the order guide g_form and reuse it in my items client script:

 

On the order guide onLoad cat client script:

this.my_order = g_form;

 

Then you can retrieve any values from this copy of the order guide in your items using cat client scripts this way on each items:

if (g_service_catalog.isOrderGuide()) {
var myVar = this.my_order.getValue('[VARIABLE NAME ON THE OG]');

...
}

 

Cheers

 

François