- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2015 01:20 PM
Is there any way to get/set the cart requested_for (which shows when checking out) from within a catalog client script? Would like to be able change the requested for while in the process of ordering (probably using a variable), and have that person's name carry over to the cart when checking out.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 06:50 AM
Jennifer,
Now a slight change in the macro. Follow as below,
1) Create a new UI macro lets say 'selected_requested_for' with below code.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_cart" object="true">
var gr = new GlideRecord("sc_cart");
gr.addQuery("user", gs.getUserID());
gr.query();
gr.next();
gr;
</g:evaluate>
<j:set var="jvar_requested_for_id" value="${jvar_cart.getValue('requested_for')}"/>
<j:set var="jvar_requested_for_name" value="${jvar_cart.getDisplayValue('requested_for')}"/>
<g:macro_invoke macro="sc_catalog_requested_for" ref="${jvar_requested_for_id}" ref_display="${jvar_requested_for_name}" />
</j:jelly>
2) In the already created macro with label type variable (as in step 2 of my previous response) just replace the macro field value to this newly created macro name selected_requested_for.
Thats it. It would do what you wanted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2015 03:00 PM
Hi Jennifer,
Since you need to override the requested_for via a variable value you can try like this.
There is an OOB macro available for capturing requested for information while ordering a service request. Just try the following steps.
- Create a variable set let's say 'Requested for details'.
- Add a new variable under the variables section inside the variable set with type as 'Macro with label' and in the type specifications tab choose the macro field value as 'sc_catalog_requested_for'.
- If you need to validate this field Create a new onSubmit catalog client script under the Catalog client script section inside the variable set with below code.
function onSubmit() {
if($('sys_display.sc_cart.requested_for').value == '') {
alert('Please select a value for "Requested for"!');
return false;
}
}
4. Once done with first 3 steps, include this variable set in all the catalog items you want this functionality
Now whatever the value selected in this macro variable will be mapped to Requested for in the ordered service request item.
Please try and do let me know if any questions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 06:01 AM
Hi Guhan,
Thanks very much for this information, this is exactly what I was looking for.
One question - do you know if there's a way to se the value of the variable on the item = the "Request for" widget value on the main page of the service catalog? So that when you first open a catalog item, the requested for variable defaults to whatever name was on the catalog page, but then allows the user to change the name if needed.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 06:50 AM
Jennifer,
Now a slight change in the macro. Follow as below,
1) Create a new UI macro lets say 'selected_requested_for' with below code.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_cart" object="true">
var gr = new GlideRecord("sc_cart");
gr.addQuery("user", gs.getUserID());
gr.query();
gr.next();
gr;
</g:evaluate>
<j:set var="jvar_requested_for_id" value="${jvar_cart.getValue('requested_for')}"/>
<j:set var="jvar_requested_for_name" value="${jvar_cart.getDisplayValue('requested_for')}"/>
<g:macro_invoke macro="sc_catalog_requested_for" ref="${jvar_requested_for_id}" ref_display="${jvar_requested_for_name}" />
</j:jelly>
2) In the already created macro with label type variable (as in step 2 of my previous response) just replace the macro field value to this newly created macro name selected_requested_for.
Thats it. It would do what you wanted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2015 11:17 AM
This worked perfectly, thanks again!