var userID = $Crm.user.id;
console.log("userID==>", userID);
var userName = $Crm.user.first_name; // + " " + $Crm.user.last_name;
console.log("userName==>", userName);
var module = $Page.module;
console.log("module==>", module);
var module_recordID = $Page.record_id;
console.log("module_recordID==>", module_recordID);
var owner = ZDK.Page.getField('Owner').getValue();
console.log("owner==>", owner);
var ownerID = ZDK.Apps.CRM.Users.fetchById(owner.id);
console.log("owner==>", owner);
// Construct the map to include both fields you want to update
pop_details = ZDK.Apps.CRM.POP_Requests.fetchById(module_recordID);
console.log("pop_details==>", pop_details);
var created_time = ZDK.Page.getField('Created_By').getValue();
console.log("created_time==>", created_time);
var created_date = ZDK.Page.getField('Created_Date').getValue();
console.log("created_date==>", created_date);
var currentDate = new Date();
var currentDateOnly = currentDate.toISOString().split("T")[0];
console.log("Current Date Only:", currentDateOnly);
var createdDateObj = new Date(created_date);
var currentDateObj = new Date(currentDateOnly);
var diffMs = currentDateObj - createdDateObj;
console.log("diffMs ==>", diffMs);
var diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
console.log("diffDays ==>", diffDays);
var aging_fiels = currentDateOnly - created_date;
console.log("aging_fiels ==>", aging_fiels);
var map = {
"Last_Viewed_User_ID": userID,
"Aging_Field" : diffDays
};
console.log("User ID: " + userID);
// Prepare data for the API call
var datalist = [];
datalist.push(map);
var param = { "data": datalist };
// API call to update the record in Zoho CRM
var response = ZDK.Apps.CRM.Connections.invoke(
"crmconn",
"https://www.zohoapis.com/crm/v5/" + module + "/" + module_recordID,
"PUT",
2,
param,
{}
);
$Client.refresh();
console.log("Response: ", response);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter