Add a field to the Service Portal shopping cart and map it to the field in the request record

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2018 01:34 AM
Hi,
How can I map a field from the Service Portal shopping cart to the field of the corresponding request record?
So I went to the 'sc_cart' page and created a duplicate of the 'SC Shopping Cart' widget. In the new copy, I went to 'Angular ng-templates' -> 'large_shopping_cart.html' and added the following lines:
<label for="cost-code">${Cost Code}</label>
<sn-record-picker id="cost-code" field="c.costCode" table="'cmn_cost_center'" display-field="'code'" value-field="'sys_id'" search-fields="'code'" page-size="100" ></sn-record-picker>
Now how do I map it to the custom field in the request table, in the same way, that Deliver to maps to a deliver_to field in the sc_request table?
I looked at the server and client script in the 'SC Shopping Cart' widget and the 'SPCart' script include and I can't figure out how to map these fields.
I appreciate all the help you can give me.
- Labels:
-
Request Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 01:15 AM
Just had to resolve the same issue myself. In the server-side code of your version of the SC Shopping Cart widget insert a series of 'request.setValue' calls right after the line which creates the 'request' object. Send them to the request record with request.update() and you're done.
If this reply is helpful or answers your question please mark it so. I'm trying to catch up to Chuck Tomasi sometime in this life span.
if (input && input.action === "checkout") {
cart.setSpecialInstructions(input.additionalDetails);
cart.setRequestedFor(input.cart.requested_for);
cart.setDeliveryAddress(input.deliverTo);
var request = cart.placeOrder();
// code to populate custom fields
request.setValue('u_location', data.location);
request.setValue('u_department', data.department);
request.setValue('u_validator_group', data.validator_group);
request.setValue('u_it_poc', data.it_poc);
request.setValue('u_building', data.building);
request.setValue('u_room', data.room);
request.setValue('u_vip', data.vip);
request.update();
data.requestData = {
number: request.getValue("number"),
table: request.getTableName(),
sys_id: request.getUniqueValue()
}
cart.setSpecialInstructions("");
cart.setRequestedFor(userID);
cart.setDeliveryAddress("");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2021 02:15 AM
Steps to modify the Service Portal > Cart > Proceed to Checkout.
You'll need to modify other code/clone widgets to cover off the other 'Proceed to Checkout' and 'Order Now' buttons.
Tested on a Rome OOTB instance.
Step 1
Add the custom field to the sc_request table.
Step 2
Clone the widget 'SC Shopping Cart'
In the HTML add
<div class="col-sm-12">
<label for="cost_centre">Cost centre:</label>
<textarea ng-model="c.data.cost_centre" id="cost_centre"></textarea>
</div>
In the server script function getCartCheckoutModal change
embeddedWidgetId: 'sc-checkout'
to something like
embeddedWidgetId: 'sc-checkout-v2'
Add the widget to the sc_cart portal page.
Step 3
Clone the widget 'Catalog Checkout' and set the id to 'sc-checkout-v2'.
In the server script function checkoutCart, after 'var request = cart.checkoutCart(true)' add:
var req = new GlideRecord('sc_request');
if (req.get(request.request_id.toString())) {
req.[your custom field name] = input.cost_centre;
req.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2023 04:51 PM
Hello @Kit Cheong,
Can you share the complete sc-checkout-v2 file. I have followed your instructions and it just causes my widget to hang on submit.