$env API
$env API is used to get the application name (FSA for iPad, FSA for Android Tablets, and FSA for Windows).
$env.get(callback_function(response) {
}
);
Where
response is the result of $env.get request. This can be a string with the following possible values:
• For FSA: FSA_MFL, FSA_ANDROID, and FSA_IPAD
• For ServiceMax Go: ServiceMaxGO
• For SFM Web delivery:
◦ When SET007 (Module: SFM Transaction Manager; Submodule: SFM Transaction Delivery Engine) is set to True, then the response is - ServiceMaxGO. If you want response as LightningDelivery , refer to the below platform function.
◦ When SET007 (Module: SFM Transaction Manager; Submodule: SFM Transaction Delivery Engine) is set to False, then the response is - Browser - ${browserName} ${browserVersion}. Example: browserName – Chrome, browserVersion - 80.0.3987.122.
In case of SFM Lightning Delivery, the $env API should use platform function to get the application name.
$env.platform(callback_function(response) {
}
);
where the response is LightningDelivery
Example
Sample request for $env API is mentioned below:
$env.get(function(res){
}
);
Sample response for $env API is mentioned below:
“FSA_MFL”
Example 1
$sfm_records.SetFieldValue() API is not supported in SFM Delivery and is supported only in FSA or Go app. Use $env API as mentioned in the following example to avoid failure of the snippet in SFM Delivery.
$env.get(function(environment) {
if (environment.toUpperCase().indexOf('BROWSER') == -1) {
$sfm_records.setFieldValue(request, result => {
console.log(JSON.parse(result));
});
}
});
From the above snippet by using $env.get() API, we avoid calling unsupported API i.e $sfm_records.setFieldValue() on SFM Delivery.
Example 2
The following example uses $env.get() API to know the error response from different platforms (FSA or Go or SFM Delivery).
$env.get(function(environment) {
var result = {
status: 'error',
error: 'Validation_error',
error_message: 'Environment == ' + environment + '-------- Time overlapped with ' + names.join(", ") + ' and ' + conflictLocalLaborLines.length + ' unsynced records',
}
$response(result);
});
Example 3
The following example describes how to use $env.get() API$env.get() API to execute common snippets with response structure of sfm_records.getRecods() API containing different structures across different platforms(Go and FSA).
$env.get(function(environment) {
If (environment === ‘FSA_IPAD’ || environment === ‘FSA_ANDROID’|| environment === ‘FSA_MFL’) {
//Add the logic for FSA app
} else if (environment === ‘ServiceMaxGO’) {
//then add the logic for Go app
} else {
//add the logic for SFM Delivery.
}
});
Example 4
The following example describes how to use $env. platform() with $env.get() for supporting $env API across different products.
if($env.platform !== undefined || $env.platform !== null){
$env.platform(function(environment) {
if(environment === 'ServiceMaxGO'){
//add the logic for Go app
} else if(environment === 'LightningDelivery'){
//add the logic for SFM Lightning Delivery
}
});
} else {
$env.get(function(environment) {
//environment: Output will be "ServiceMaxGO" only
});
}