- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎09-08-2016 03:16 PM
If you want to add a new field when sc_layout is disabled, then, check this: Legacy:Adding a Field to the Service Catalog Checkout - ServiceNow Wiki.
This document is also written on the same lines, with Cart layouts enabled.
So, lets take an example of adding a Company field to the checkout below the Requested for field:
This field will then pass the value of that field to the Company field of the Service Catalog Request.
This example makes the following assumptions.
- This example is for an instance using two-step checkout with new cart layout v2. If two-step checkout is not enabled, enable it
- This example populates the Company field on the Service Catalog Request form. If the field does not appear on the form, configure the form
To add a field to the Service Catalog Checkout:
Go to System UI > UI Macros and create a new UI Macro named sc_cart_view_company.
In the XML editor, add the following 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">
<j:if test="${jvar_cart.isEmpty() != 'true'}">
<input type="HIDDEN" name="cart_id" id="cart_id" value="$[sc_cart.sys_id]" />
<div class="container">
<div class="row col-xs-12 sc_cv_info_row">
<div class="col-xs-2 sc_requested_label">
${gs.getMessage('Company')}
</div>
<div class="col-xs-8">
<g2:ui_reference name="core_company" table="core_company" onchange="setCartValue()"/>
</div>
</div>
</div>
</j:if>
</j:jelly>
Now, navigate to System UI > UI Pages and select the servicecatalog_checkout_one_v2 UI Page. Add this script to the Client script field:
function setCartValue() {
var newField = gel('core_company');
var myCart = gel('cart_id');
var cart_item = new GlideRecord('sc_cart_item');
cart_item.addQuery('cart', myCart.value);
cart_item.query();
if(cart_item.next()) {
cart_item.hints = "<hints><entry key='sysparm_processing_hint' value='setfield:request.company=" + newField.value + "'/></hints>";
cart_item.update();
}
}
- For this example, the reference field was called core_company, and the field being populated on the request is company. If different fields are used:
- Find this line: var company = gel('core_company');
- In the line that starts with 'cart_item.hints' replace 'request.company' with the name of the field to be populated on the request ticket where 'request' is the request being generated and 'company' is the name of the field.
- Now navigate to Service Catalog > Maintain Cart Layouts and select Target type: Browser Screen > Cart Preview Screen (Two Step).
- Go to Widget Macros tab, Select Edit and add the UI Macro created "sc_cart_view_company" from the list collector.
- Update the Order(say, 650) of the created macro to decide its position relative to other macros.
If i missed something, or some corrections, any kinda queries are always welcome.
- 3,567 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This works great, but do you have to do if you want to add multiple fields to the Cart Layout?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I got it, thanks.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks a lot deepakgarg, got it working!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for this! one issue though, how do we deal with newfield.value having single quotes or other characters that will otherwise blow up the XML? Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello James,
Could you use one of the following tags to help you out there:
${JS:expression}
${HTML:expression}
You can even combined them together like so: ${JS,HTML:expression}. The prefix tells the system to take the result of the expression and escape it before outputting.
Hope this helps!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It's working for admins but not for non-admins. What could be the reason?
It leaves the field blank after checkout