- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
So when I started integrating with FedEx - I probably had the only thing in mid - Use the Track API given by FedEx and build something which consumes this API. Then I looked at the docs here and saw a Vancouver release feature which was just amazing to use!
I started to configure it but did not know where to start. And the documentation is kind of landed me in the gray area - each time I read it more. So here I am listing down step by step process to configure it in your own or one of the customer instances.
Doc to refer (Washington release) - https://docs.servicenow.com/bundle/washingtondc-it-asset-management/page/product/hardware-asset-mana...
Before starting with the configuration steps, important things first:
The workspace view below displays the Shipment records (which needs to be tracked) and the Integration profile (this is what you will configure to connect to your 3rd party API's)
Navigate to Workspaces --> Asset Workspace (or Hardware Asset Workspace) --> Shipment to hop on to the below form
So lets begin the steps for configuration (I did it for FedEx API's):
Step 1: Create a script Include which is an extension of Out-of-box Script Include "ITAMShipmentIntegration". Create a function "fetchShipmentInfo" in the script include with the logic to talk to the external carrier API. For now execute it in the testing mode (without connecting to any API yet) with the code as below
if (mode == 'test') {
var obj = {
httpResponseCode: 200,
httpResponseMessage: "SUCCESS"
};
return obj;
}
Follow the settings for the newly created script include as mentioned in the documentation here
Step 2: Click the "Test Connection" UI Action button on the Carrier profile as below. Populate Name and API fields with requisite values and Job will be created after the Test connection is executed successfully.
The job is responsible for calling the fetchShipmentInfo function and populating the latest tracking details once the live connection to tracking API is made.
Step 3: Do not forget to connect the Integration profile with the Shipping carrier record as below
Step 4: Make a live connection to your Tracking API. In my case, I created a SUBFLOW for calling the REST API of FedEx Tracking API as in below code.
Things to remember:
a) All the tracking numbers (multiple) are in the parameters of fetchShipmentInfo function and these tracking numbers have to be passed as a input to the Carrier Track API
b) Once you have the tracking numbers in an array pass it as your Track API expects it to be (see below 👇 for the example I passed for FedEx)
var fedExTrackingUtil = Class.create();
fedExTrackingUtil.prototype = Object.extendsObject(sn_itam_common.ITAMShipmentIntegration, {
initialize: function() {},
fetchShipmentInfo: function(trackingNumbers, mode) {
gs.info("fedex tracking nos"+trackingNumbers);
//Mode - "TEST"
if (mode == 'test') {
var obj = {
httpResponseCode: 200,
httpResponseMessage: "SUCCESS"
};
return obj;
} else {
//MODE - "API Call"
var trackingDetails = [];
//***************BEGIN - Call SUBFLOW to connect FedEx Track Shipment API *****************************/
try {
var inputs = {};
inputs['tracking_numbers'] = trackingNumbers; // Array.String
// Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
// sn_fd.FlowAPI.getRunner().subflow(<Subflow technical name>).inBackground().withInputs(inputs).run();
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow(<Subflow technical name>).inForeground().withInputs(inputs).run();
var outputs = result.getOutputs();
// Get Outputs:
// Note: outputs can only be retrieved when executing synchronously.
trackingDetails = outputs['trackingDetails']; // Array.Object
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
//************************************END*********************************************************/
this.processResponse(trackingDetails);
return output;
}
},
type: 'fedExTrackingUtil'
});
Step 5: Once you have the response from the Subflow then call the function processResponse in your script include.
While invoking "processResponse" function, the parameter to be passed is the response in the below format:
[
{trackingNumber: <ABC>, deliveryDate: <value>, pickupDate: <value>, packageStatus: <value>, statusDetail: <value>, trackingURL: <value>}
{trackingNumber: <XYZ>, deliveryDate: <value>, pickupDate: <value>, packageStatus: <value>, statusDetail: <value>, trackingURL: <value>},
.....
]
I already composed the above Array of objects format in my subflow output so it was easy for me.
Step 6: Set the scheduled job created in step above as per your requirements. All the shipments in transit state and tagged to the specific carrier will be updated with the tracking details.
Please provide your feedback on this article in comments. Features for creating labels, picking up requests etc are not yet but will soon be coming in releases ahead.
Note: This feature requires a subscription , so please contact your Sales rep/Account Executive before starting with this feature.
- 4,451 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
