The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Where does the Shipping Address get pulled from?

Michael Bachme1
Kilo Guru

Where does the Shipping Address at Service Catalog checkout get pulled from?

1 REPLY 1

dev_vijaysnowhy
Giga Contributor

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:




  1. // Insert below code after line 106 - c.requestedFor = {...};  
  2. c.deliverTo = c.data.deliverTo;  
  3.  
  4. $scope.$on("field.change", function(evt, parms) {  
  5.   if (parms.field.name == 'requested_for') {  
  6.       c.data.cart.requested_for = parms.newValue;  
  7.       /* This is new code */  
  8.       c.server.get({  
  9.           action: "update_deliver_to",  
  10.           name: parms.newValue  
  11.       }).then(function(response) {  
  12.           c.deliverTo = response.data.deliverTo;  
  13.       });  
  14.       /* End of new code */  
  15.   }  
  16. });  

Server Script:




  1. // Insert below code after line 7 - var cart = new SPCart(input.cartName, userID);  
  2. data.deliverTo = getDeliveryAddress(userID);  
  3.  
  4. if (input && input.action === "update_deliver_to") {  
  5.   data.deliverTo = getDeliveryAddress(input.name);  
  6. }  
  7.  
  8.  
  9. // Insert below code after line 62 - data.cartItems = cart.getItems();  
  10. function getDeliveryAddress(requestedFor) {  
  11.   var deliveryAddress = '';  
  12.   var userObject = gs.getUser().getUserByID(requestedFor);  
  13.   var location = userObject.getLocation();  
  14.  
  15.   var cmnLocationGR = new GlideRecord('cmn_location');  
  16.   cmnLocationGR.addQuery('sys_id', location);  
  17.   cmnLocationGR.query();  
  18.  
  19.   if (cmnLocationGR.next()) {  
  20.       locationAddress = {  
  21.           name: cmnLocationGR.getValue('name'),  
  22.           street: cmnLocationGR.getValue('street'),  
  23.           city: cmnLocationGR.getValue('city'),  
  24.           postcode: cmnLocationGR.getValue('zip')  
  25.       };  
  26.  
  27.       if (locationAddress.name && locationAddress.name != '')  
  28.           deliveryAddress = locationAddress.name + '\n';  
  29.  
  30.       if (locationAddress.street && locationAddress.street != '')  
  31.           deliveryAddress += locationAddress.street + '\n';  
  32.  
  33.       if (locationAddress.city && locationAddress.city != '')  
  34.           deliveryAddress += locationAddress.city + '\n';  
  35.  
  36.       if (locationAddress.postcode && locationAddress.postcode != '')  
  37.           deliveryAddress += locationAddress.postcode;  
  38.  
  39.       return deliveryAddress;  
  40.   }  
  41. }  

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:




  1. {  
  2.       "cartTemplate": "custom_large_shopping_cart.html"  
  3. }  


And unless I'm forgetting something, that's it!