No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Add the Code to Call the Action
We’ll add the code that calls the Create_Delivery action by using the REST API.
- Navigate to the Shipify-Node-App directory
where you downloaded the Shipify Web application. Copy the file shipment_with_action_api_call.js to file shipment.js.
- On a Windows computer, the command would be: copy shipment_with_action_api_call.js shipment.js
- On a Mac OS computer, the command would be: cp shipment_with_action_api_call.js shipment.js
- Enter this command to get the files ready to commit: git add —A
- Enter this command to commit the changes along with a comment: git commit —m 'MyChangeComments'If you’re working from a Windows computer, you may need to replace the single quotes with double quotes (").
- Enter this command to deploy the app to Heroku: git push heroku master
If you look at the code to create the delivery record, you’ll
see that it passes the invoice ID and does a POST to the /quickActions/Create_Directory resource.
1Shipment.prototype.createDelivery = function createDelivery(so) {
2 var self = this;
3 var authorization = this._formatAuthHeader(so.authorization);
4 if(!so.invoiceId) {
5 var err = new Error("Must Pass InvoiceId to Ship!");
6 err.statusCode = '400';
7 err.err = err.message;
8 this.emit('create-delivery', err);
9 return;
10 }
11 var quickActionBody = {
12 contextId: so.invoiceId,
13 record: {
14 Order_Number__c: so.orderNumber
15 }
16 };
17
18 var deliveryReq = {
19 url: so.instanceUrl + '/services/data/v29.0/
20 sobjects/Invoice__c/quickActions/Create_Delivery/',
21 method: 'POST',
22 headers: {
23 'Authorization': authorization,
24 'Content-Type': 'application/json'
25 },
26 body: JSON.stringify(quickActionBody)
27 };
28
29 //Make Ajax request and emit 'create-delivery'
30 //with result data or error back to listner.
31 request(deliveryReq, this.handleAJAXResponse(
32 'create-delivery'));
33};We’ve got our API call all ready to go, so let’s test it out by shipping a customer order.