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
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);
if(!(res.results[i].SVMXC__Service_Order__r in wo_Map))
if (eachLaborLine['SM_EU_Actual_Line_Type__c'].fieldvalue.value.includes("Labor", 0))
Let me know if any of you need any help regarding Custom JS Code snippet or you can reach-out to any JS DEV.
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