$sfm_records.setFieldValue API
$sfm_records.setFieldValue API is used to update any field in header and child records of the current SFM. It is mandatory to include $response in $sfm_records.setFieldValue API after it is successfully executed.
* 
$sfm_records.setFieldValue API does not support insert or delete operations and supports only update operation.
$sfm_records.setFieldValue(request, callback)
{

};
Where
request is the JSON object with values to be updated in the SFM data on edit SFM process. This request structure includes following fields:
header: To update the header record
details: To update the details records
sectionId refers to detail page section like Parts, Labor, Travel and Expense. We can get the value of sectionId from $sfm_records.get API .
index represents the record position in the detail lines (Parts or Labor or Expense or Travel)
fields represents the fields to update from header and detail records
callback is the callback function used to update $response API with 'success' or 'error' message
Sample request of $sfm_records.setFieldValue API is mentioned below:
var request={
"header": {
"fields": [
{
"name": "SVMXC__City__c",
"value": "Bangalore"
}
,
{
"name": "SVMXC__Is_Entitlement_Performed__c",
"value": "true"
}
,
{
"name": "Currency__c",
"value": "1234567.897"
}
,
{
"name": "SVMXC__Scheduled_Date__c",
"value": "2019-04-16"
}
,
{
"name": "SVMXC__Actual_Resolution__c",
"value": "2019-04-16 10:52:04"
}
,
{
"name": "URL__c",
"value": "Servicemax.com"
}
,
{
"name": "Phone__c",
"value": "08025223616"
}
,
{
"name": "SVMXC__Component__c",
"value": "a0N0R0000003w82UAA"
}
,
{
"name": "CustomMultiPL__c",
"value": "Jan;Feb;Mar"
}
]
}
,
"details": {
"a0f0R000000idvYQAQ" : [
{
"index": "0",
"fields":
[
{
"name": "SVMXC__Billable_Quantity__c",
"value": "2000"
}
,
{
"name": "SVMXC__Activity_Type__c",
"value": "Service"
}
,
{
"name": "SVMXC__From_Location__c",
"value": "a270R000005qAoTQAU"
}
,
{
"name": "MultiPicklist__c",
"value": "Multi Picklist Val 01;Multi Picklist Val 02"
}
,
{
"name": "SVMXC__Product__c",
"value": "01t0R000002nFyfQAE"
}

]
}
,
{
"index": "1",
"fields":
[

{
"name": "SVMXC__Activity_Type__c",
"value": "Service"
}
,
{
"name": "SVMXC__From_Location__c",
"value": "a270R000005qAoTQAU"
}
,
{
"name": "MultiPicklist__c",
"value": "Multi Picklist Val 01;Multi Picklist Val 02"
}
,
{
"name": "SVMXC__Product__c",
"value": "01t0R000002nFyfQAE"
}

]
}
],
"a0f0R000000idvZQAQ" :
[
{
"index": "0",
"fields":
[
{
"name": "SVMXC__Work_Description__c",
"value": "test1"
}

]
}
,
{
"index": "1",
"fields":
[
{
"name": "SVMXC__Work_Description__c",
"value": "test2"
}

]
}
]
}
};
$sfm_records.setFieldValue(request,(res)=>{
var currentRecord=JSON.parse(res);
console.log('setFieldValue response in snippet:',currentRecord);
var result = {
status: 'success',
error: '',
error_message: '',
}
$response(result);
}
);
Where
res is the result of $sfm_records.setFieldValue.
error_message is the error message to be displayed in the client application.
Sample response structure of $sfm_records.setFieldValue API is mentioned below:
{
"header": {
"response": {
"status": "fail",
"error": "{"status":"error","error":"SVMX_CS_002","error_message":"Invalid Parameter
: CreatedDate,SVMXC__Order_Status__c__key"}",
"data": ""
}
},
"details": {
"sectionId1": [
{
"index": "0",
"response": {
"status": "success",
"error": "",
"data": ""
}
},
{
"index": "1",
"response": {
"status": "success",
"error": "",
"data": ""
}
}
],
"sectionId2": [
{
"index": "0",
"response": {
"status": "success",
"error": "",
"data": ""
}
},
{
"index": "1",
"response": {
"status": "success",
"error": "",
"data": ""
}
}
]
}
}
Was this helpful?