First of all JS Code Snippet feature sounds very DOPE. But it works like .....meh!.
Don't get me wrong I am posting this after using/working/developing with Servicemax for more than a year now.
Few points I want to share here are
Don't get confuse, although the work/flow/functionality of ServiceMax GO, Servicemax FSA Desktop, ServiceMax FSA for Android Tablet and on WEB are almost same. But here is the catch, development went different for each of them means though the features are same doesn't mean the responses will get same for each API. Means $sfm_records.get API's response is different in every platform for On Exit event for lookup fields.
Even at Servicemax end they have different engineering team for different platform and they are managing in such a way that none of them not yet synced for a complete feature yet.
Don't use .getTime() for Date type of object in code, that will give you error on Servicemax GO, although that will work on FSA + WEB. FIX for that:
var startF = parsedRecord.currentRec['SVMXC__Start_Date_and_Time__c'];
var endF = parsedRecord.currentRec['SVMXC__End_Date_and_Time__c'];
var currRecStartDate = ((startF.fieldvalue && startF.fieldvalue.value) || startF);
var currRecEndDate = ((endF.fieldvalue && endF.fieldvalue.value) || endF);
Don't check for key in object like if(! res.results[i].SVMXC__Service_Order__r in wo_Map) , it will pass on WEB but won't work any where else. Event it won't show any error also cause statement is not wrong. Fix for that:
if(!(res.results[i].SVMXC__Service_Order__r in wo_Map))
Check/record the response before you proceed for the code change. Cause some fields which are coming on WEB may not available on FSA or Servicemax GO. Like for $event.get API response rowIndex is available on WEB but not in FSA, Id is available in FSA but on WEB its id(not Id).
To check string contains substring .contains won't work here. Fix for that:
if (eachLaborLine['SM_EU_Actual_Line_Type__c'].fieldvalue.value.includes("Labor", 0))
For debugging we can use these
WEB - CTRL + SHIFT + I
FSA Desktop - ALT + CTRL + SHIFT + J (got this after very long time of effort)
Servicemax GO Android - setup ADB on PC + cmd > adb logcat (its a lengthy process just search on youtube "how to debug android app using cmd")
The sample code in help docs and on community portal won't work even after hefty modification so write down your own one.
Let me know if any of you need any help regarding Custom JS Code snippet or you can reach-out to any JS DEV.