i have a contact entity dob,age fields. During onsave my account all the age in contact entity update based on my dob field.But only using batch process to bulk update my record in contact.
i have no other example on how to use batch process in javascript.
debugger;
var now = new Date();
var today = new Date().getFullYear();
var odata = "$select=ContactId,new_age,new_dob&$filter=new_dob ne null";
var age = new Date().getFullYear();
SDK.REST.retrieveMultipleRecords("Contact", odata, function(results) {
debugger;
for (var i in results) {
var res = results[i].new_dob;
var newage = results[i].new_age;
var contactid = results[i].ContactId;
var birthyear = res.getFullYear();
if (birthyear != null) {
age=today-birthyear;
update(age, contactid)
}
}
}, errorHandler, function() {});
function errorHandler(error) {
writeMessage(error.message);
}
function update(age, contactid) {
var contact = {};
contact.new_age = age;
SDK.REST.updateRecord(contactid, contact, "Contact", function() {}, errorHandler);
}