Need help with my script

Hi Guys ,

Thanks for the support , and for such a wonderful software . I am planning to filter a link field data and I am able to do that with the below script ,

{
frappe.ui.form.on("TC", "refresh", function(frm) {
    cur_frm.set_query("ht", function() {
        return {
            "filters": {
                "p1": cur_frm.doc.prodorder 
            }
        };
    });
});
}

now I would like to put some kind of OR function here , if the prodorder field value is there either in p1 field or p2 field or in p3 field, the link should work .

How to achieve this ? Can someone guide me please ?

Thanks

Edit :

Tried accomplishing with the below script , but it only checks the p2 field , kindly guide me .

{
frappe.ui.form.on("TC", "refresh", function(frm) {
    cur_frm.set_query("ht", function() {
        return {
            "filters": {
                "p1||p2": cur_frm.doc.prodorder 
            }
        };
    });
});
}

Thanks

Guys any help ?

Thanks

Just tried digging further , and the below script works like an AND function , I mean only if it satisfies both the condition the doc is getting displayed in the filter , could anyone just guide me on how to make it work like an OR function , atleast if one condition is satisfied it should get displayed. e.g prodorder should be either equal to p1 or p2 .

{
frappe.ui.form.on("TC", "refresh", function(frm) {
    cur_frm.set_query("ht", function() {

return {
            "filters": {
                "p1": cur_frm.doc.prodorder ,
                "p2": cur_frm.doc.prodorder ,
            }
        };

    });
});
}

Please guide . Thanks

@Muthu,

please refer the Calling a Different Method to Generate Results.

Thanks, Makarand

Thanks for the reply @makarand_b . I already saw that example but could not figure out exactly how that could suite my requirement. Anyway I will give a try and let you know on that . If possible could you kindly tell me how do I use OR function in my case ?

Thanks

Hi @makarand_b . Tried customizing to my requirement https://frappe.github.io/frappe/user/en/guides/app-development/overriding-link-query-by-custom-script . But it is not working .

Kindly guide

Thanks

can you share what you have tried ?

1 Like

Thanks for swift response .@makarand_b Yes sure

frappe.ui.form.on("TC", "onload", function(frm){
cur_frm.set_query("ht", function() {
    return {
        query: "erpnext.controllers.queries.ht_query",
        filters: cur_frm.doc.prodorder === "p1" ?
            {"cur_frm.doc.prodorder": "p2"} : {"cur_frm.doc.prodorder": "p3"}
    };
});

});

you will need to write the py method ht_query in queries.py file and then write your custom query where you can add the or condition to get the filtered values.

You can find the similar example in queries.py file

Thanks, Makarand

Thanks for quick reply dear @makarand_b. I am not familiar with server scripting so I am trying to stick with client js scripting . Please could you guide me with client scripting . Just guide me on how do I use an OR function in the above filters , that would help me .

Please guide me

Thanks

Guys any help ? I am struggling with this for more than a day .

Please someone help me .

Thanks in advance

Hi All ,

I tried filtering with this script , no errors in the console but this is not filtering anything , it displays all the results .Could anyone indicate me where I am going wrong ?

{
frappe.ui.form.on("VAVE", "refresh", function(frm) {
    cur_frm.set_query("ht", function() {
        if(frm.doc.prodorder == frm.doc.p1)
{
return {
            "filters": {
                "p1": cur_frm.doc.prodorder 
            }
        };
}
    });
});
}

Please help

Thanks