Help with writing filters in custom script

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.



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-forum+un...@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.
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';
}

On 04-Feb-2014, at 8:14 PM, lxnow wrote:

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.




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-forum+un…@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.



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-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/35C6B743-5CBA-43A2-B508-D7B8C1EFA8E3%40gmail.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Thanks Nabin! Used #2 for for hosted version. Works like a charm.

On Thursday, February 6, 2014 1:22:52 PM UTC+8, Nabin Hait wrote:
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';
}

On 04-Feb-2014, at 8:14 PM, lxnow wrote:

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.




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-forum+un…@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.



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-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4f296409-9b49-488b-b32f-125040cc8bcc%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.