API: $fetch
$fetch: This API issues authenticated outbound calls to Salesforce REST API as logged in user. This is to enable MAS to send and retrieve data from Salesforce without providing credentials again. The outbound call is made directly from the ServiceMax Go app to Salesforce and not through the sync gateway. The sample $fetch code is as follows:
var activitySpaceInit = async function ()
{

const params = await $getInitParams();
displayFetchDetails(params);
};


var displayFetchDetails = function (params)
{

const {
recordId }
= params || {
};

const {
instanceUrl }
= (params && params.authParams) || {
};

$fetch(‘${
instanceUrl}/services/data/v20.0/sobjects/SVMXC__Service_Order__c/${
recordId}
’, {

headers: {
'Content-Type': 'application/json' }, method: 'PATCH’, body: JSON.stringify(data)
})
// just pass on res as-is, convert error to something that can be displayed to user when stringified
.then((res) => res.json()).catch((e) => ({ [e.name]: e.message }))
// log the WO details
.then((val) => {
$log(‘record details’ JSON.stringify(val, null, 2));
});
};
When the activity space uses the new APIs, such as $getInitParams and $fetch, the technicians must perform a Reset App after they upgrade the app to 1.6.0.
{
"attributes": {
"type": "SVMXC__Service_Order__c",
"url": "/services/data/v20.0/sobjects/SVMXC__Service_Order__c/a1d1R00000BsjbuQAB"


},
"Id": "a1d1R00000BsjbuQAB",
"OwnerId": "0051R00000HhpM4QAJ",
"IsDeleted": false,
"Name": "WO-00000705",
"CurrencyIsoCode": "USD",
"RecordTypeId": "0121R000000SY6RQAW",
"CreatedDate": "2020-08-26T14:17:01.000+0000",
"CreatedById": "0051R00000HhpM4QAJ",
"LastModifiedDate": "2020-09-03T18:58:48.000+0000",
"LastModifiedById": "0051R00000IAYz6QAH",
"SystemModstamp": "2020-09-03T18:58:48.000+0000",
"LastActivityDate": "2020-09-02",
"SVMXC__Acknowledged_By_Technician_Date_Time__c": null,
"SVMXC__Actual_Initial_Response__c": null,
"SVMXC__Actual_Onsite_Response__c": "2020-09-03T18:33:49.000+0000",
"SVMXC__Actual_Resolution__c": null,
"SVMXC__Actual_Restoration__c": null,
"SVMXC__Age_Bucket__c": "8 To 15 days",
"SVMXC__Age__c": 9,
"SVMXC__Apply_Business_Hours_For_OptiMax__c": false,
"SVMXC__Appointment_Promised_Time_Slot__c": null,
"SVMXC__Auto_Entitlement_Status__c": null,
"SVMXC__BatchUpdate__c": null,
"SVMXC__Billing_Type__c": null,
"SVMXC__Booked_Appointment_Slot__c": null,
"SVMXC__Canceled_Date_Time__c": null,
"SVMXC__Case__c": "5001R00000nOEcPQAW",
"SVMXC__City__c": "Oakland",
"SVMXC__Clock_Paused_Forever__c": false,
"SVMXC__Closed_By__c": null,
"SVMXC__Closed_On__c": null,
"SVMXC__Company__c": "00136000004peWhAAI",
"SVMXC__Contact__c": "003360000071Z16AAE",
"SVMXC__Corrective_Action__c": null,
"SVMXC__Country__c": "United States",
"SVMXC__Customer_Down_Status__c": "No",
"SVMXC__Customer_Down__c": false,
"SVMXC__Dispatch_Now__c": "No",
"SVMXC__Dispatch_Status__c": "New",
"SVMXC__Drip__c": false,
"SVMXC__Driving_Time__c": null,
"SVMXC__EndpointURL__c": "https://johnsmith-dev-ed.my.salesforce.com/services/Soap/c/7.0/00D36000000K2wF",
"SVMXC__Invoice_Created__c": false,
"SVMXC__Invoice_Number__c": null,
"SVMXC__IsPartnerRecord__c": false,
"SVMXC__IsPartner__c": "False",
"SVMXC__Is_Entitlement_Performed__c": false,
"SVMXC__Is_Exported__c": false,
"SVMXC__Is_PM_Work_Order__c": false,
"SVMXC__Is_SLA_Calculated__c": false,
"SVMXC__Is_Service_Covered__c": false,
"SVMXC__Last_Dispatch_Event__c": null,
"SVMXC__Latitude__c": 37.750539,
"SVMXC__Locked_By_DC__c": false,
"SVMXC__Longitude__c": -122.202873,
"SVMXC__Number_Of_Times_Assigned_Bucket__c": "Less Than 2 Times",
"SVMXC__Number_Of_Times_Queued_Bucket__c": "Less Than 2 Times",
"SVMXC__Number_Of_Times_Scheduled_Bucket__c": "Less Than 2 Times",
"SVMXC__OptiMax_Error_Occurred__c": true,
"SVMXC__OptiMax_Error_Text__c": "Primary territory for this work order could not be calculated. This could be because either no territory matching rules were defined, this work order did not match any territory match rules, or a matching territory rule did not yield any territories for this work order.",
"SVMXC__OptiMax_Last_Run_Time__c": null,
"SVMXC__OptiMax_Status__c": null,
"SVMXC__Optimizer_Connection_Name__c": null,
"SVMXC__Order_Status__c": "Open",
"SVMXC__Order_Type__c": "Depot Repair",
"SVMXC__PM_Plan__c": null,
"SVMXC__PM_SC__c": null,
"SVMXC__PM_Tasks_Created__c": false,
"SVMXC__Perform_Auto_Entitlement__c": false,
"SVMXC__Root_Cause__c": null,
"SVMXC__SESSION_ID__c": "00D36000000K2wF!ARkAQMhlcGOG6gLUD99jXucCE.DF.5i1EcED1QUthu_PW2UQ0LxUx3PkX.ofjklCAq1KKMTvTmPFrr9d0bsAWfUeh63DMKkq",
"SVMXC__SLA_Clock_Paused__c": false,
"SVMXC__SLA_Terms__c": null,
"SVMXC__Schedule_As_A_Dependent_Work_Order__c": false,
"SVMXC__Scheduled_Date__c": "2020-09-03",
"SVMXC__State__c": "California",
"SVMXC__Street__c": "7000 Coliseum Way",
"SVMXC__Time_Between_Assign_And_Schedule_Bucket__c": "Less Than 2 hours",
"SVMXC__Time_Between_Queue_And_Assign_Bucket__c": "Less Than 2 hours",
"SVMXC__Time_Between_Schedule_And_Close_Bucket__c": "Less Than 2 hours",
"SVMXC__Time_To_Close_c__c": null,
"SVMXC__Time_to_Assign_Bucket__c": "Less Than 2 hours",
"SVMXC__Time_to_Queue_Bucket__c": "Less Than 2 hours",
"SVMXC__Time_to_Schedule_Bucket__c": "Less Than 2 hours",
"SVMXC__Turnaround_Time__c": "More Than 30 days",
"SVMXC__Work_Order_Scheduling_Status__c": null,
"SVMXC__Work_Performed__c": null,
"SVMXC__Zip__c": "95621",
"SVMXC__Total_Billable_Amount__c": 0,
"SVMXC__Total_Estimate__c": 0,
"SVMXC__Total_Work_Order_Cost__c": 0,
"SVMXC__SM_Estimated_Duration__c": 0,
"SVMXC__SM_In_Jeopardy__c": false,
"SVMXC__SM_LJS_Minimum_Schedule_Duration__c": 150,
"SVMXC__SM_Ok_To_Arrive_Early__c": false,
"SVMXC__SM_Optimizer_Message_Creation_Date_Time__c": null,
"SVMXC__SM_PM_Activity__c": null,
"SVMXC__SM_Revised_Duration__c": 0,
"SVMXC__SM_Schedule_Violation_Penalty__c": null,
"SVMXC__SM_Scheduled_Duration__c": 0,
"SVMXC__SM_Scheduling_Options__c": "JDM and LJS Enabled",
"SVMXC__SM_Scope_Change__c": 0,
"Z_Checkbox__c": false,
"SM_Crew_Name__c": null,
"SM_Multi_resource__c": false,
"SM_Version_Number__c": 2,
"SVMXC__SM_Crew_Assignment__c": false,
"SVMXC__SM_Integration_Source__c": "Local",
"SVMXC__SM_Life_Cycle_Status__c": null,
"SVMXC__SM_Multi_resource__c": false,
"SVMXC__SM_Version_Number__c": 2,
"Checkbox_Field__c": false,
"Zinc_External_ID__c": "smax-workorder-a1d1R00000BsjbuQAB",
"Snehacustomobjectlookup__c": null,
"Checkbox_custom_field1__c": false,
"Formula_Status_Field__c": "XXX",
"SVMXC__SM_Is_Change_Order__c": false,

}
Was this helpful?