Continuing on my RESTlet adventure the external ve...
# suitescript
n
Continuing on my RESTlet adventure the external vendor will send me training updates on employees like employeeID, completeDate and/or lastLoginDate and/or resultAcheived The vendor might send employee ID plus 1,2 or 3 of the other values. What is a good way to set the properties for record.SubmitFields. I can successfully update the employee when all three are provided but if one of the values is not sent, then those fields get set to null using my current method. I'm thinking there must be a way to set only the properties I need each time. This is what I'm doing currently: var updateFieldsObj = new Object; updateFieldsObj.type='customrecord_enrolments'; updateFieldsObj.id=employeeID; updateFieldsObj.values ={ 'custrecord_login_active':Login, 'custrecord_progress':lastLoginDate, 'custrecord_date_completed':resultAcheived }; var updated = record.submitFields(updateFieldsObj);
b
buildup updateFieldsObj.values one key / value pair at a time
if there is no value, dont add it to the updateFieldsObj.values object
n
that's where I came unstuck. I tried using updateFieldsObj.values.push(..) but said push is not a function.
when I tried UpdateFieldsObj.values= then I was overwriting and only getting the final vlaue
b
dont overwrite the object, define new properties/keys
n
For defining new property keys I tried updateFieldsObj.values('custrecord_login_active')=Login
b
that will probably throw an error about how updateFieldsObj.values is not a function
n
yes, exactly
b
go through though the link i gave you to learn how objects work
n
cheers
b
there is a way to modify an existing object, and it does not use parenthesis
n
I used a series of these: if(courseProgress){ valuesObj.custrecord_progress=courseProgress; }
s
That approach mostly works, unless you have a boolean property. If you do, you should use util.isBoolean(property) or some similar function to make sure you have a real true or false value, and not just a truthy or falsy value, like an empty string or undefined (both of those would be evaluated as false in a simple if clause)
n
@scottvonduhn thanks for this. From @erictgrubaugh NS Curriculum I've been working through freecodecamp and it's good to see all these functions getting applied.
high five 1