nikzz
July 27, 2018, 2:04pm
1
I am trying to pass if condition as a filter in frappe.call as i want to get data from that field whose checkbox is selected.
fields: ['mobile'],
filters: {
if(product_1==1)
{'product': 'Product 1'}
else if(product_2==1)
{'product':'Product 2'}
}
else
{'product':'Product 3'}
},
But i’m getting error. Is it right to filter data via normal js ??
If No, then any idea on how to get the data corresponding to that checkbox.
Thank You
Put the if condition outside of frappe call.
Use a variable to store value based on your if condition and pass it as value in filters
1 Like
nikzz
July 27, 2018, 2:34pm
3
frappe.ui.form.on("Group SMS", "onload", function(frm) {
if('product_1'==1)
{
var zz='Product 1';
}
else if('product_2'==1)
{
var zz = 'Product 2';
}
else
{
var zz = 'Product 3';
}
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Dummy User",
fields: ['mobile'],
filters: {'product':zz}
},
#more code
But its giving error. Guess that my variable is not able to get through frappe.call.
Also tried filters: {'product': 'zz'}
and filters: {'product': 'zz'},
But still the same result
Initialize zz outside if condition like var zz = “”;
Not sure if that’s the error though
nikzz
July 27, 2018, 2:52pm
6
The send sms button also stops showing.
Statically it was like
shahid
July 27, 2018, 3:06pm
10
@nikzz sorry to interrupt you but i am wondering that how are you using ERPnext directly through localhost? without entering port 8080?
Can you please share the trick?
nikzz
July 28, 2018, 4:33am
12
Tried this. Although console.log is giving value inside frappe.call for var zz but on passing this varibale inside filter as :
filters: {'product' : zz }
is still giving error.
nikzz:
is still giving error.
sorry what is the error?
Can post your full code for frappe.call
nikzz
July 28, 2018, 4:51am
14
frappe.ui.form.on("Group SMS", "onload", function(frm) {
var zz = "";
if(frm.doc.product_1==1)
{
var zz='Product 1';
}
else if(frm.doc.product_2==1)
{
var zz = 'Product 2';
}
else
{
var zz = 'Product 3';
}
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:'Dummy User',
//filters: {'product': zz},
fields: ['mobile']
},
callback: function(r) {
var a=r.message;
var qq =JSON.stringify(a);
//console.log(a[0]['mobile']);
var dat= JSON.parse(qq);
var mobile_num= dat.map(x =>x.mobile);
console.log(mobile_num);
frm.add_custom_button(__("Send SMS"), function(click) {
var event_type=cur_frm.doc.before_save;
$.ajax({
url: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx........", # my api
data: {
"event_type": event_type,
}
});
});
}
});
});
And error is same, in console: Unable to handle success response
nikzz
July 28, 2018, 4:57am
15
I got something, actually to do so, I first had to save it. But I want it to be dynamic, ie, without clicking on save i want the variable to be selected.
Any help ?
After saving and refreshing, i get the value in filter but I want that to be happening on realtime without clicking on save and refreshing the page.
I think your error is in handling response. You may be getting the checkbox value after it’s checked. See network tab in developer tools what args are passed
nikzz
July 28, 2018, 6:33am
17
Yeah thats what I’m saying. After selecting checkbox and clicking on save , I get the value. But what I want is on clicking checkbox, i get the value instantaneously without clicking save.
ok can you show your oncheck event function for the checkbox?
Like below
frappe.ui.form.on("Group SMS", "product", function(frm){
//you code here
});
nikzz
July 28, 2018, 7:08am
19
On doing so, the “send sms” button disappears.
My code is already posted earlier. See upwards
Place the Send SMS button in refresh method and try again