Help with writing filters in custom script

89 views
Skip to first unread message

lxnow

unread,
Feb 4, 2014, 9:44:54 AM2/4/14
to erpnext-dev...@googlegroups.com
I have this script in sales order that filters the types of campaigns a user can choose depending on the customer_group of the customer, the date validity of the campaign, and the campaign approval status.  It currently looks like this:

cur_frm.fields_dict.tma_campaign.get_query = function(doc) {
    return {
filters: [
['Campaign', 'proposal_status', 'in', 'Approved'],
['Campaign', 'customer', 'in', doc.customer_group],
['Campaign', 'start_date', '<=', get_today()],
['Campaign', 'end_date', '>=' , get_today()]
]
}
}

I'd like to be able to add an OR type filter that lets me include another field that is normally mutually exclusive with the 'customer' field (bold line above); something like

['Campaign', 'national_campaign', '=', '1'],

The problem is that 'national_campaign' and 'customer' are mutually exclusive, i.e. if a campaign is 'national_campaign' = 1, then the 'customer' field would be null.

Nabin Hait

unread,
Feb 6, 2014, 12:22:52 AM2/6/14
to erpnext-dev...@googlegroups.com
There are 2 way to do it:
1) Define a function in server side code which will return the desired output for campaign field. And call that function from inside get_query:

cur_frm.fields_dict.tma_campaign.get_query = function(doc) {
return {query: "path to server side function"}
}

2. You can define the desired query in custom client side script. In this case:

  cur_frm.fields_dict.tma_campaign.get_query = function(doc) {
return 'select name from tabCampaign where proposal_status="Approved" and (customer="' + doc.customer_group + '" or national_campaign = 1) and curdate() between start_date and end_date order by name';
}

--
Note:
 
If you are posting an issue,
1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.
 
End of Note
---
You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/520dbcf7-416b-4802-8d53-2f39930086bb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

lxnow

unread,
Feb 6, 2014, 1:16:41 AM2/6/14
to erpnext-dev...@googlegroups.com
Thanks Nabin! Used #2 for for hosted version. Works like a charm.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages