Hello,
I have doctype named “Eligibility Form” and using an ERPNext workflow to change the state of the document.
Form has field named “rejection_reason” that is not a required field.
I have implemented one prompt on “Reject” Action.
Prompt has one field named “reason” that is mendatory.
I don’t want to allow change the state from “In Progress” to “Rejected” without having the “rejection_reason”.
How can I stop workflow to change the state if there is no reason of rejection?
Following is my code in script:
frappe.ui.form.on("Eligibility Form", "before_save", function(frm, cdt, cdn){
if (frm.doc.workflow_state== "Rejected" && frm.doc.workflow_state.indexOf("Rejected") == 0){
frappe.prompt([
{
fieldtype: 'Small Text',
reqd: 1,
fieldname: 'reason',
label: 'Reason for rejecting'
}],
function(args){
validated = 1;
frappe.call({
method: 'frappe.core.doctype.communication.email.make',
args: {
doctype: frm.doctype,
name: frm.docname,
subject: format(__('Reason for {0}'), [frm.doc.workflow_state]),
content: args.reason,
send_mail: false,
send_me_a_copy: false,
communication_medium: 'Other',
sent_or_received: 'Sent'
},
callback: function(res){
if (res && !res.exc){
frappe.call({
method: 'frappe.client.set_value',
args: {
doctype: frm.doctype,
name: frm.docname,
fieldname: 'rejection_reason',
value: frm.doc.rejection_reason ?
[frm.doc.rejection_reason, frm.doc.workflow_state].join('\n') : frm.doc.workflow_state
},
callback: function(res){
if (res && !res.exc){
frm.reload_doc();
}
}
});
}
}
});
},
__('Reason for ') + frm.doc.workflow_state,
__('End as Rejected')
)
}
});