To disable the fields in a sublist for the status in line field is approved:
this function is added in the lineInit of Client script.
/**
* This function will be used to lock the lines when the status is pending approval.
* It will disable the editing for the line.
* @param {*} currentRecord //scriptContent.currentRecord
* @param {*} subListId //scriptContext.sublistId
* @param {*} fieldsToDisable //Object of Fields for the given sublist
*/
function lockLinesStatusApproval(currentRecord, subListId, fieldsToDisable) {
try {
let approvalStatus = currentRecord.getCurrentSublistValue({
sublistId: subListId,
fieldId: fieldsToDisable.STATUS
});
let selectedLine = currentRecord.getCurrentSublistIndex({
sublistId: subListId
});
if (approvalStatus === ‘2’) {
// show alert and disable editing for the current line.
alert(‘This line is locked as it is Pending Approval. No further edits are allowed.’);
Object.values(fieldsToDisable).forEach(function (fields) {
let fieldToDisable = currentRecord.getSublistField({
sublistId: subListId,
fieldId: fields,
line: selectedLine,
});
fieldToDisable.isDisabled = true;
});
} else {
// If the status is not pending approval, enable the fields for editing
Object.values(fieldsToDisable).forEach(function (fields) {
let fieldToDisable = currentRecord.getSublistField({
sublistId: subListId,
fieldId: fields,
line: selectedLine,
});
fieldToDisable.isDisabled = false;
});
}
} catch (e) {
log.error(‘Error @ lockLinesStatusApproval’, e);
}
}
the above function is used to disable all fields in the sublist with sublist: ‘sublistsId’.
fieldsToDisable is an object of fields conatining the fieldIds:
fieldsToDisable ={
VENDOR: ‘custrecord_jj_brv_sub_vendor’,
ACCOUNT: ‘custrecord_jj_brv_ven_account’,
DATE: ‘custrecord_jj_brv_ven_date’,
AMOUNT: ‘custrecord_jj_brv_ven_amount’,
TDS_CODE: ‘custrecord_jj_brv_ven_tds_code’,
TDS_AMOUNT: ‘custrecord_jj_brv_ven_tds_amount’,
NET_AMOUNT: ‘custrecord_jj_brv_ven_net_amount’,
MEMO: ‘custrecord_jj_brv_ven_memo’,
STATUS: ‘custrecord_jj_brv_ven_status’,
APPROVED_BY: ‘custrecord_jj_brv_ven_approved_by’,
JE_CREATED: ‘custrecord_jj_brv_ven_je_created’,
LINKED_JOURNAL: ‘custrecord_jj_brv_ven_linked_je’,
JE_CREATION_ERROR: ‘custrecord_jj_brv_ven_error’
}