Where does the Shipping Address get pulled from?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 06:44 AM
Where does the Shipping Address at Service Catalog checkout get pulled from?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 06:53 AM
Hello Michael
I got this answer from community hope this might be helpful
I've been working on this today as it's a requirement of ours too.
This is my working code. It loads the logged in user's delivery address when they enter the cart. If the 'Requested for' field changes, the new user's delivery address is pulled through.
SC Shopping Cart
Client Script:
- // Insert below code after line 106 - c.requestedFor = {...};
- c.deliverTo = c.data.deliverTo;
- $scope.$on("field.change", function(evt, parms) {
- if (parms.field.name == 'requested_for') {
- c.data.cart.requested_for = parms.newValue;
- /* This is new code */
- c.server.get({
- action: "update_deliver_to",
- name: parms.newValue
- }).then(function(response) {
- c.deliverTo = response.data.deliverTo;
- });
- /* End of new code */
- }
- });
Server Script:
- // Insert below code after line 7 - var cart = new SPCart(input.cartName, userID);
- data.deliverTo = getDeliveryAddress(userID);
- if (input && input.action === "update_deliver_to") {
- data.deliverTo = getDeliveryAddress(input.name);
- }
- // Insert below code after line 62 - data.cartItems = cart.getItems();
- function getDeliveryAddress(requestedFor) {
- var deliveryAddress = '';
- var userObject = gs.getUser().getUserByID(requestedFor);
- var location = userObject.getLocation();
- var cmnLocationGR = new GlideRecord('cmn_location');
- cmnLocationGR.addQuery('sys_id', location);
- cmnLocationGR.query();
- if (cmnLocationGR.next()) {
- locationAddress = {
- name: cmnLocationGR.getValue('name'),
- street: cmnLocationGR.getValue('street'),
- city: cmnLocationGR.getValue('city'),
- postcode: cmnLocationGR.getValue('zip')
- };
- if (locationAddress.name && locationAddress.name != '')
- deliveryAddress = locationAddress.name + '\n';
- if (locationAddress.street && locationAddress.street != '')
- deliveryAddress += locationAddress.street + '\n';
- if (locationAddress.city && locationAddress.city != '')
- deliveryAddress += locationAddress.city + '\n';
- if (locationAddress.postcode && locationAddress.postcode != '')
- deliveryAddress += locationAddress.postcode;
- return deliveryAddress;
- }
- }
Create a new Angular ng-template by duplicating large_shopping_cart-html. custom_large_shopping_cart.html: Make the new template the default: Service Portal Designer > Shopping Cart > Edit 'SC Shopping Cart' widget > Menu > Open in platform > Additional options, JSON format:
- {
- "cartTemplate": "custom_large_shopping_cart.html"
- }
And unless I'm forgetting something, that's it!