@shahid_ecit
I think below code may solve your purpose. In below example, I have written the code for Item DocType where when workflow state is Approved then it will display a message Approved. So, you can play around with this.
frappe.ui.form.on("Item", "validate", function(frm) {
if (frm.doc.workflow_state=="Approve")
{
frappe.msgprint("Approve Clicked");
}
else if (frm.doc.workflow_state=="Reject")
{
frappe.msgprint("Reject Clicked");
}
});
@ruchin78 your answer is good but; if @shahid_ecit used the logic below may will be better because the workflow_state may not equal the “approve” or “reject” itself it may contains it in the string such as approved by HR Manager or rejected by HR Manager so to search a substring in the workflow_state may be better.
frappe.ui.form.on('You Doctype', {
refresh: function(frm) {
frm.add_custom_button(__('Approve'), function(){
frappe.confirm(
'Are you sure to Approve?',
function(){
///this will run upon YES click
},
function(){
// this will run on NO click
window.close();
}
);
},__("ACTIONS"));
frm.add_custom_button(__('Reject'), function(){
frappe.confirm(
'Are you sure to Reject?',
function(){
///this will run upon YES click
},
function(){
// this will run on NO click
window.close();
}
);
},__("ACTIONS"));
}
});
@shahid i want to recycle rejected doc and this is not what i ment
what i want is i want a js code that will look like this
$('.class_of_button').click(function(){
alert("you have clicked it");
});
@saeedkola you said the way i wanted but one difference is i dont want to add new button named actions but when we add a workflow to a doctype there will be a action button so i dont want to create it but in that action there will be state that we specified in workflow for example
@shahid_ecit Create field in your doctype with named “status” with field type Select & put your all Workflow states in its option.
and put that field name in workflow like below
& use js like
frappe.ui.form.on("Your Doctype",
{
status: function(frm){
my_fun(frm);
}
});
var my_fun = function(frm)
{
if(frm.doc.status == "Approved"){
frappe.msgprint("This is Approved");
}
else if(frm.doc.status == "Rejected"){
frappe.msgprint("This is Rejected");
}
}