cancel
Showing results for 
Search instead for 
Did you mean: 

Custom JS Code Snippet till 31-12-2020

deepak_mylist
Line Chef
Line Chef

Custom JS Code Snippet till 31-12-2020

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

  1. 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.
    Spoiler
    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.
  2. 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);​
  3. 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))
  4.  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).
  5. 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))​
  6. 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")
  7. 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.

0 Likes
Reply
dbrieck
Sushi Chef
Sushi Chef

User Reply Custom JS Code Snippet till 31-12-2020 dbrieck

I have a custom object I would like to query against via a button on a work order SFM. I'm having trouble with the beginning of the snippet. The console doesn't like $event.get  or $sfm_records.get.

There's very little documentation on this feature or even a basic 'Hello World' example.

 

$sfm_records.get(function(unsavedSfmRecordString) {
    var unsavedSfmRecord = JSON.parse(unsavedSfmRecordString);
    console.log('in snippet: sfm_record response = ', unsavedSfmRecord);
	var currentRecordId = unsavedSfmRecord.currentRec['Id'];

    var filterCondition1 = {
      sequence : 1,
      left_operand : 'Equipment__c',
      operator : '=',
      right_operand : [currentRecordId],
      right_operand_type : 'Value'
    };

    var filterCondition2 = {
	  "sequence": 2,
	  "left_operand": "Status__c",
	  "operator": "=",
	  "right_operand": [
		"Open"
	  ],
	  "right_operand_type": "Value"
	}

    var query_object = {
      object : 'SM_Work_Order__c',
      fields : ['External_ID__c', 'Name', 'Due_Date__c'],
      filter : [filterCondition1, filterCondition2],
      Order : [{queryField: 'Name', sortingOrder: 'ASC'}],
      AdvancedExpression : '(1 AND 2)'
    };

    $db.get(query_object, function(query_object, res) {
      console.log('in snippet : db response = ', res);
      if (!res.error) {
        if (res.results) {

          $env.get(function(environment) {
			  var result = {
				status: 'success',
				error: 'SM Found',
				error_message: ''
			  };
            $response(result);
          })
        } else {
          var result = {
            status: 'success',
            error: '',
            error_message: 'SM not found'
          };
          $response(result);
        }
      }
    })
  })

 

 

JSEE Error while performing EVAL! Please check for syntax error in the JS snippet! =>ReferenceError: $sfm_records is not defined

Tags (1)
0 Likes
Reply