This article serves to address unintentional closure of transaction record when the Close button is accidentally pressed.
A possible approach is to remove the standard Close button in the record, and replace it with a customized Close button. The customized Close button will pop-up a confirmation message from the user, and will ask for a reason for closing the record.
Below is an overview of how this can be implemented:
I. Customize your form to remove the Close button.
*Configuring Buttons and Actions (Answer Id: 10108)
II. Create a User Event script that will dynamically add a customized Close button, in view mode.
III. Create a Client Script that will contain the functions that should be executed, when the customized button is added.
*Trigger a Function in Client-side Script in View Mode by Button Added Using User Event Script
a. Load the current record using api record.load(options).
b. You can use the native javascript function confirm() , to verify with the user if he wants to continue closing the record.
c. If the confirm() returns true, check if the record has the ‘close reason’ field populated.
d. If not populated, you can use the native javascript function prompt(), to ask for ‘close reason’. Store the value, then use the api record.setValue(options) to set the field.
e. Continue closing the record.
f. Submit the changes made to the record using API record. save(options).
g. To see the updated record, you can use location.reload() native javascript function.
var curRec = currentRecord.get();
var rec = record.load({
type: record.SALES_ORDER,
id: curRec.id
})
var reason = rec.getValue({
fieldId: 'custbody10'
})
var r = confirm("Are you sure you want to close?");
if(r){
//Check if a reason for closure has been provided. If not ask for a reason.
if (reason == "" || reason == null){
var input_reason = prompt('Please enter closing reason');
rec.setValue({
fieldId:'custbody10',
value:input_reason
})
}
for (var i = 1; i<=rec.getLineCount({fieldId:'item'}); i++){
rec.setSublistValue({
sublistId:'item',
fieldId:'isclosed',
line:i,
value:'T'
})
}
rec.save()
location.reload()
}else{
alert('No changes made')
}