This code iterates through the fields object to find and process the custrecord_project_status field. If conditions involving the project’s current status and a new charity status are met, it ensures the project status remains set to PROJECT_COMPLETED.
if fields = {
custrecord_project_status: setNewProjectStatus,
custrecord_project_parent_charity_status: newCharityStatus,
};
for (var key in fields) {
if (checkForParameter(key) && (key == 'custrecord_project_status')) {
var projectStatusValue = search.lookupFields({
type: 'customrecord_projects',
id: relatedProjects[i],
columns: ['custrecord_project_status']
});
let currentProjectStatus = projectStatusValue.custrecord_project_status[0].value;
if ((Number(currentProjectStatus) === PROJECT_COMPLETED) && (checkForParameter(newCharityStatus)) && INELIGIBLE_CHARITY_STATUS.includes(Number(newCharityStatus))) {
fields.custrecord_project_status = PROJECT_COMPLETED;
}
}
}
record.submitFields({
type: ‘customrecord_projects’,
id: relatedProjects[i],
values: fields,
});