Population of list values in a virtual list field in the fieldchange of another field.
if (scriptContext.fieldId === “custrecord_vr_svcord_pps”) {
let ppsRec = currentRec.getValue({
fieldId: “custrecord_vr_svcord_pps”,
});
if (ppsRec) {
setTimeout(function () {
try {
let ppsLookUp = search.lookupFields({
type: “customrecord_vr_pps”,
id: Number(ppsRec),
columns: [
“custrecord_jj_st_custom_turnaround_time” // Custom Turn Around Time field
],
});
let validateFlag = currentRec.getValue({
fieldId: “custrecord_jj_validated_flag”,
});
let routineFlag = currentRec.getValue({
fieldId: “custrecord_jj_routine_flag”,
});
if (routineFlag && validateFlag) {
console.log(“ENTER”)
processingType = “Routine – Validated”;
let virtualField = currentRec.getField({
fieldId: “custpage_virtual_field”,
});
console.log(“virtual field”, virtualField)
if (virtualField) {
console.log(“6666”)
virtualField.isMandatory = true;
}
}
else if (routineFlag && !validateFlag) {
processingType = “Routine – Non-Validated”;
let virtualField = currentRec.getField({
fieldId: “custpage_virtual_field”,
});
if (virtualField) {
virtualField.isMandatory = false;
}
}
else if (!routineFlag && validateFlag) {
processingType = “Non-Routine – Validated”;
let virtualField = currentRec.getField({
fieldId: “custpage_virtual_field”,
});
if (virtualField) {
virtualField.isMandatory = true;
}
}
else if (!routineFlag && !validateFlag) {
processingType = “Non-Routine – Non-Validated”;
let virtualField = currentRec.getField({
fieldId: “custpage_virtual_field”,
});
if (virtualField) {
virtualField.isMandatory = false;
}
}
let radiationType = currentRec.getValue({ fieldId: “custrecord_jj_svo_radiation_type” });
// Define possible values for the virtual list field
let listValues = [];
console.log(“custom TAT”, ppsLookUp.custrecord_jj_st_custom_turnaround_time)
if (ppsLookUp.custrecord_jj_st_custom_turnaround_time) {
console.log(“***”)
listValues.push(ppsLookUp.custrecord_jj_st_custom_turnaround_time);
}
// Add specific options based on Processing Type and Radiation Type conditions
if (processingType == “Routine – Validated” && radiationType == 1) {
listValues = listValues.concat([
“Standard – 5 Day”,
“Standard DEA – 2 Day”,
“24 Hr RUSH”,
“4 Hr RUSH”,
“2 Hr RUSH”,
“1 Hr RUSH”
]);
}
else if (processingType == “Routine – Validated” && radiationType == 2) {
listValues = listValues.concat([
“X-Ray Standard – 30 Days”
]);
}
else if (processingType == “Routine – Non-Validated” && radiationType == 1) {
listValues = listValues.concat([
“Standard – 5 Day”,
“24 Hr RUSH”,
“4 Hr RUSH”,
“2 Hr RUSH”,
“1 Hr RUSH”,
“Rad.Tol.Study – 10 Day”,
“Rad.Tol.Study RUSH – 5 Day”
]);
}
else if (processingType == “Routine – Non-Validated” && radiationType == 2) {
listValues = listValues.concat([
“Rad.Tol.Study X-Ray – 60 Days”
]);
}
else if (processingType == “Non-Routine – Validated” && radiationType == 1) {
listValues = listValues.concat([
“DVS Standard – 10 Day”,
“DVS RUSH – 4 Day”,
“DVS RUSH – 2 Day”
]);
}
else if (processingType == “Non-Routine – Validated” && radiationType == 2) {
listValues = listValues.concat([
“DVS X-ray – 15 Day”
]);
}
else if (processingType == “Non-Routine – Non-Validated” && radiationType == 1) {
listValues = listValues.concat([
“Standard Services”,
“RUSH Services”
]);
}
else if (processingType == “Non-Routine – Non-Validated” && radiationType == 2) {
listValues = listValues.concat([
“Standard Services”,
“RUSH Services”
]);
}
// Populate the virtual list field with the values
let selectField = currentRec.getField({ fieldId: “custpage_virtual_field” });
if (selectField) {
// Clear any existing options in the select field
selectField.removeSelectOption({ value: null });
selectField.insertSelectOption({
value: ”,
text: ”
});
// Add each option from listValues to the select field
listValues.forEach(value => {
selectField.insertSelectOption({
value: value,
text: value
});
});
}
let sublistObj = currentRec.getSublist({
sublistId: “recmachcustrecord_vr_svcord_item”
});
let columnObj = sublistObj.getColumn({
fieldId: “custrecord_vr_svcord_item_item”
});
if (flags.validateFlag) {
SETTINGS.setItemFields(scriptContext);
columnObj.isDisabled = false;
} else {
UI_CONTROLLER.removeItemLines(scriptContext)
console.log(“hid column”)
columnObj.isDisabled = true;
console.log(“column obj”, Object.keys(columnObj))
}
UI_CONTROLLER.hideLoadingSymbol();
} catch (error) {
log.error(“Error @PPS sourcing”, error);
UI_CONTROLLER.hideLoadingSymbol();
}
}, 50);
}