Update opportunity fields when quotation action is approved by work flow from front end using custom script

Hey Folks,
I want to update my opportunity sales stage field when sales manager approved quotation from action button.I want to update the field using custom script.Here the problem is i am not able to catching when user click on action approve or reject button.I tried on_submit,workflow_state but both are not working.

Code which i have already tried
//1.
frappe.ui.form.on(“Payment Entry”, {
workflow_state: function(frm) {
if (frm.doc.workflow_state == “Approved”) {
//update opportunity field
}
}
});

//2.
frappe.ui.form.on(“Payment Entry”,“on_submit”, {
function(frm) {
if (frm.doc.workflow_state == “Approved”) {
//update opportunity field
}
}
});

//3.
frappe.ui.form.on(“Payment Entry”, {
on_submit: function(frm) {
if (frm.doc.workflow_state == “Approved”) {
//update opportunity field
}
}
});

//4.
frappe.ui.form.on(“Payment Entry”, {
on_submit: function(frm,cdn,cdt) {
if (frm.doc.workflow_state == “Approved”) {
//update opportunity field
}
}
});

Please help thanks in advanced.

Approved in your workflow is submit right?

Write script for on submit, and use following code to update Opportunity field.

frappe.db.set_value("Opportunity", "opportunity_name", "opportunity_field_name", "Value to be updated");

Thanks for reply @shahid but on click of action button, on_submit event is not triggered.This is the actual problem.

share your code.

frappe.ui.form.on(“Quotation”, “on_submit”, function(frm, cdt, cdn) {
console.log(‘event triggered’);
})

If my event is triggered somehow, then my task will be done. @shahid

Event should triggered when i click on action button approved/ reject. Remeber i am using workflow.

Your Script is correct not sure why not triggering with workflow,
try server script.

It is a requirement that we should have do it from client site.I know we can do it using server side by python.

Solved ! Here is the right answer
frappe.ui.form.on(‘Quotation’, {
after_workflow_action: (frm) => {
if(frm.doc.workflow_state == ‘Approved’){
let opportunityName = frm.doc.opportunity;
frappe.db.set_value(“Opportunity”, opportunityName, “sales_stage”, “Proposal Submitted”);
}
}
})

“after_workflow_action” is the event which triggered when action button clicked.

1 Like

Hi, I also have a problem with workflows. I created a workflow and ticked the checkbox “Don’t Override Status” so that the workflow state show as the status and will not be only on a draft status while the document is in the process of approval.

However, the other status like Overdue, Deliver & Bill, Closed and Paid are not shown if the checkbox “Don’t Override Status” unless you uncheck it but the draft status is shown which leads to confusion.

Another scenario I read is, if these other statuses were not on the workflow, you cannot open the document unless you deactivate the workflow. But I haven’t tested that scenario.

What ways can I solve this?