Help with validation for Cost Center and Chart of Account selection on Purchase Order screen

Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
    // Get all line-items for the selected PO
    var el = getchildren('Purchase Order Item',doc.name,'po_details');
    // Go through each line item
    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Cost Center",
                filters: {name:el[i].cost_center},
                fieldname:["company_name"]
            },
            callback: function(r) {
                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Account",
                filters: {name:el[i].expense_head},
                fieldname:["company"]
            },
            callback: function(r) {
                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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.

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

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:
Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
    // Get all line-items for the selected PO
    var el = getchildren('Purchase Order Item',doc.name,'po_details');
    // Go through each line item
    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Cost Center",
                filters: {name:el[i].cost_center},
                fieldname:["company_name"]
            },
            callback: function(r) {
                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Account",
                filters: {name:el[i].expense_head},
                fieldname:["company"]
            },
            callback: function(r) {
                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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.

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

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?

Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server

Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:
Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:
Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
    // Get all line-items for the selected PO
    var el = getchildren('Purchase Order Item',doc.name,'po_details');
    // Go through each line item
    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Cost Center",
                filters: {name:el[i].cost_center},
                fieldname:["company_name"]
            },
            callback: function(r) {
                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Account",
                filters: {name:el[i].expense_head},
                fieldname:["company"]
            },
            callback: function(r) {
                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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.

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

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?

Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server

Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:
Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:
Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement. I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
// Get all line-items for the selected PO
var el = getchildren('Purchase Order Item',doc.name,'po_details');
// Go through each line item
var mycompany ="";
for(var i in el){
// Check for the company of Cost Center
wn.call({
method:"webnotes.client.get_value",
args: {
doctype:"Cost Center",
filters: {name:el[i].cost_center},
fieldname:["company_name"]
},
callback: function(r) {
mycompany=r.message.company_name;
if (doc.company != mycompany) {
msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
validated = false;
}
}
});

// Check for the company of Expense Code (Account Code)
wn.call({
method:"webnotes.client.get_value",
args: {
doctype:"Account",
filters: {name:el[i].expense_head},
fieldname:["company"]
},
callback: function(r) {
mycompany=r.message.company;
if (doc.company != mycompany) {
msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
validated = false;
}
}
});


}

}
Thanks in advance for your help.

Kind regards,
MP



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.

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.

    For more options, visit https://groups.google.com/groups/opt_out.
Thanks a lot Nabin. This is what I was looking for.

I will try it out.

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 05:22:32 UTC+1, Nabin Hait wrote:

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?

Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server

Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:
Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:
Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
    // Get all line-items for the selected PO
    var el = getchildren('Purchase Order Item',doc.name,'po_details');
    // Go through each line item
    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Cost Center",
                filters: {name:el[i].cost_center},
                fieldname:["company_name"]
            },
            callback: function(r) {
                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Account",
                filters: {name:el[i].expense_head},
                fieldname:["company"]
            },
            callback: function(r) {
                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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.

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.

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

Did you mean write custom_validate() method under Custom Script with Script Type=Server? or Did you mean write custom_validate() method on the server in purchase_order.py file?

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 10:00:49 UTC+1, MP wrote:
Thanks a lot Nabin. This is what I was looking for.

I will try it out.

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 05:22:32 UTC+1, Nabin Hait wrote:

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?

Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server

Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:
Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:
Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:

1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.
3. Is there a better way to check for this kind of validation?
Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

cur_frm.cscript.custom_validate = function(doc) {
    // Get all line-items for the selected PO
    var el = getchildren('Purchase Order Item',doc.name,'po_details');
    // Go through each line item
    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Cost Center",
                filters: {name:el[i].cost_center},
                fieldname:["company_name"]
            },
            callback: function(r) {
                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].cost_center +'\'' +' is not a valid ' +'department code for '+ doc.company +'.');
                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:"webnotes.client.get_value",
            args: {
                doctype:"Account",
                filters: {name:el[i].expense_head},
                fieldname:["company"]
            },
            callback: function(r) {
                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint('<b>' + '\'' +el[i].expense_head +'\'' +' is not a valid ' +'expense code '+ doc.company +'.');
                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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.

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.

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

In custom script with script type as server.

On 9 Oct 2013 19:11, "MP" <ma...@gmail.com> wrote:
Hi Nabin,

Did you mean write custom_validate() method under Custom Script with Script Type=Server? or Did you mean write custom_validate() method on the server in purchase_order.py file?

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 10:00:49 UTC+1, MP wrote:
Thanks a lot Nabin. This is what I was looking for.

I will try it out.

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 05:22:32 UTC+1, Nabin Hait wrote:

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?


Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server


Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:

Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:

Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:


1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement. I think it is because of For loop but I am not sure how to break out of it. I can't use break statement under if clause.

  1. Is there a better way to check for this kind of validation?
    Please note we are still using older version of ERPNext. We haven't migrated to Responsive branch yet.

    cur_frm.cscript.custom_validate = function(doc) {

    // Get all line-items for the selected PO
    var el = getchildren(‘Purchase Order Item’,doc.name,‘po_details’);
    // Go through each line item

    var mycompany ="";
    for(var i in el){
    // Check for the company of Cost Center
    wn.call({
    method:"webnotes.client.get_value",
    args: {

             doctype:&quot;Cost Center&quot;,<br>                filters: {name:el[i].cost_center},<br>                fieldname:[&quot;company_name&quot;]<br>            }, <br>            callback: function(r) { <br>
    
             mycompany=r.message.company_<u></u>na<u></u>me;<br>                if (doc.company != mycompany) {<br>                    msgprint(&#39;&lt;b&gt;&#39; + &#39;\&#39;&#39; +el[i].cost_center +&#39;\&#39;&#39; +&#39; is not a valid &#39; +&#39;department code for &#39;+ doc.company +&#39;.&#39;);<br>
    
                 validated = false;    <br>                }<br>            }    <br>    });<br>                    <br>        // Check for the company of Expense Code (Account Code)<br>        wn.call({<br>            method:&quot;webnotes.client.get_<u></u>va<u></u>lue&quot;,<br>
    
         args: {<br>                doctype:&quot;Account&quot;,<br>                filters: {name:el[i].expense_head},<br>                fieldname:[&quot;company&quot;]<br>            }, <br>            callback: function(r) { <br>
    
             mycompany=r.message.company;<br>                if (doc.company != mycompany) {<br>                    msgprint(&#39;&lt;b&gt;&#39; + &#39;\&#39;&#39; +el[i].expense_head +&#39;\&#39;&#39; +&#39; is not a valid &#39; +&#39;expense code &#39;+ doc.company +&#39;.&#39;);<br>
    
                 validated = false;    <br>                }        <br>            }<br>        });<br>        <br><br>    }<br>    <br>}<br>Thanks in advance for your help.<br><br>Kind regards,<br>MP<br></div></blockquote>
    



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.

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.

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.

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

Thanks for your reply. I have created below custom script for DocType: Purchase Order, Script Type=Server. But it doesn't seems to get called at all.

    def custom_validate():
        msgprint('I got called')
        company_count = 1
        if company_count >=0 :
            msgprint('Error: Test')
            raise Exception

I tried above on both the new version of ERPNext and older version (before Responsive branch). I looked at the latest code on the server and I don't see any support for custom_validate() method. I might be wrong. Any idea what I am doing wrong?

Kind regards,
Mayur Patel


On Wednesday, 9 October 2013 16:21:02 UTC+1, Nabin Hait wrote:

In custom script with script type as server.

On 9 Oct 2013 19:11, "MP" <ma...@gmail.com> wrote:
Hi Nabin,

Did you mean write custom_validate() method under Custom Script with Script Type=Server? or Did you mean write custom_validate() method on the server in purchase_order.py file?

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 10:00:49 UTC+1, MP wrote:
Thanks a lot Nabin. This is what I was looking for.

I will try it out.

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 05:22:32 UTC+1, Nabin Hait wrote:

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?


Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server


Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:

Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:

Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:


1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can’t use break statement under if clause.

  1. Is there a better way to check for this kind of validation?
    Please note we are still using older version of ERPNext. We haven’t migrated to Responsive branch yet.

    cur_frm.cscript.custom_validate = function(doc) {

    // Get all line-items for the selected PO
    var el = getchildren(‘Purchase Order Item’,doc.name,‘po_details’);
    // Go through each line item

    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:“webnotes.client.get_value”,
            args: {

                doctype:“Cost Center”,
                filters: {name:el[i].cost_center},
                fieldname:[“company_name”]
            },
            callback: function® {

                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint(’<b>’ + ‘’’ +el[i].cost_center +’’’ +’ is not a valid ’ +‘department code for ‘+ doc.company +’.’);

                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:“webnotes.client.get_value”,

            args: {
                doctype:“Account”,
                filters: {name:el[i].expense_head},
                fieldname:[“company”]
            },
            callback: function® {

                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint(’<b>’ + ‘’’ +el[i].expense_head +’’’ +’ is not a valid ’ +‘expense code ‘+ doc.company +’.’);

                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP



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+unsubscr…@googlegroups.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.

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.

    For more options, visit https://groups.google.com/groups/opt_out.
It should be def custom_validate(self):, remaining part looks correct.

On 09-Oct-2013, at 9:04 PM, MP wrote:

Hi Nabin,

Thanks for your reply. I have created below custom script for DocType: Purchase Order, Script Type=Server. But it doesn't seems to get called at all.

    def custom_validate():
        msgprint('I got called')
        company_count = 1
        if company_count >=0 :
            msgprint('Error: Test')
            raise Exception

I tried above on both the new version of ERPNext and older version (before Responsive branch). I looked at the latest code on the server and I don't see any support for custom_validate() method. I might be wrong. Any idea what I am doing wrong?

Kind regards,
Mayur Patel


On Wednesday, 9 October 2013 16:21:02 UTC+1, Nabin Hait wrote:

In custom script with script type as server.

On 9 Oct 2013 19:11, "MP" <ma...@gmail.com> wrote:
Hi Nabin,

Did you mean write custom_validate() method under Custom Script with Script Type=Server? or Did you mean write custom_validate() method on the server in purchase_order.py file?

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 10:00:49 UTC+1, MP wrote:
Thanks a lot Nabin. This is what I was looking for.

I will try it out.

Kind regards,
Mayur Patel

On Wednesday, 9 October 2013 05:22:32 UTC+1, Nabin Hait wrote:

Write custom server side code in custom_validate() method. The function gets executed before saving the doc.
For throwing a validation message, use webnotes. throw() method, it will raise exception and stop further processing.

On 8 Oct 2013 19:27, "MP" <ma...@gmail.com> wrote:
Hi Rushabh,

I thought server side scripts get executed after the doc has been saved. I want my validation to be done first and if there are any issues, I don't want server to save the doc. Is there anyway to call my validation (custome Script - server) on the server first and then call the save method?


Alternatively, is there anyway where on client, I can find out company value for a cost center and use it for validation on client end? I thought using wn.call I can call server method and get the data on the client end and store in a local variable? https://github.com/webnotes/wnframework/wiki/Client-side-scripting#get-values-from-server


Your help in above will be highly appreciated.

Kind regards,
MP

On Tuesday, 8 October 2013 06:01:45 UTC+1, rushabh wrote:

Mayur,

You can't use validated inside a server call - the server call is executed separately "after" the save event is fired.

This is an ideal use case for a server-side validation. Use Custom Script (server) for this and re-write the logic in Python

best,
Rushabh

On Monday, October 7, 2013 9:15:20 PM UTC+5:30, MP wrote:

Hi There,

In our system, we have multiple companies and some users have access to multiple companies. So on Purchase Order screen, we would like to do some client side validation to make sure that the cost center and account that they have selected for each item is for the select company and not other. I have written below script. But I have two issues:


1. I have used r.message.company_name to set a local variable called mycompany. I know this is not a right way to do it. So I need help with setting it in a right way.
2. I do see message box for validation when i tried to save a PO with wrong information, but system still continue with saving the doc. It seems to ignore validated=false statement.  I think it is because of For loop but I am not sure how to break out of it. I can’t use break statement under if clause.

  1. Is there a better way to check for this kind of validation?
    Please note we are still using older version of ERPNext. We haven’t migrated to Responsive branch yet.

    cur_frm.cscript.custom_validate = function(doc) {

    // Get all line-items for the selected PO
    var el = getchildren(‘Purchase Order Item’,doc.name,‘po_details’);
    // Go through each line item

    var mycompany ="";
    for(var i in el){
        // Check for the company of Cost Center
        wn.call({
            method:“webnotes.client.get_value”,
            args: {

                doctype:“Cost Center”,
                filters: {name:el[i].cost_center},
                fieldname:[“company_name”]
            },
            callback: function® {

                mycompany=r.message.company_name;
                if (doc.company != mycompany) {
                    msgprint(’<b>’ + ‘’’ +el[i].cost_center +’’’ +’ is not a valid ’ +‘department code for ‘+ doc.company +’.’);

                    validated = false;   
                }
            }   
    });
                   
        // Check for the company of Expense Code (Account Code)
        wn.call({
            method:“webnotes.client.get_value”,

            args: {
                doctype:“Account”,
                filters: {name:el[i].expense_head},
                fieldname:[“company”]
            },
            callback: function® {

                mycompany=r.message.company;
                if (doc.company != mycompany) {
                    msgprint(’<b>’ + ‘’’ +el[i].expense_head +’’’ +’ is not a valid ’ +‘expense code ‘+ doc.company +’.’);

                    validated = false;   
                }       
            }
        });
       

    }
   
}
Thanks in advance for your help.

Kind regards,
MP




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+unsubscr…@googlegroups.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.

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.

    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.

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

I tried with your suggestion too and it still doesn't work. See below. It should at least display 'I got called' when I click on Save the document but it doesn't. Are you sure there is support for custom_validate method on server? If so, could you please tell where on server it is? Thanks.

def custom_validate(self):
        msgprint('I got called')
        company_count = 1
        if company_count >=0 :
            msgprint('Error: Test')
            raise Exception
Kind regards,
MP

On Wednesday, 9 October 2013 19:24:20 UTC+1, Nabin Hait wrote:
It should be def custom_validate(self):, remaining part looks correct.




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.

    For more options, visit https://groups.google.com/groups/opt_out.
Mayur - please post your code in gist / pastebin

the padding is important - the code must be padded by one tab.


W: https://erpnext.com
T: @rushabh_mehta

On 10-Oct-2013, at 1:44 PM, MP <ma...@gmail.com> wrote:

Hi Nabin,

I tried with your suggestion too and it still doesn't work. See below. It should at least display 'I got called' when I click on Save the document but it doesn't. Are you sure there is support for custom_validate method on server? If so, could you please tell where on server it is? Thanks.

def custom_validate(self):
        msgprint('I got called')
        company_count = 1
        if company_count >=0 :
            msgprint('Error: Test')
            raise Exception
Kind regards,
MP

On Wednesday, 9 October 2013 19:24:20 UTC+1, Nabin Hait wrote:
It should be def custom_validate(self):, remaining part looks correct.





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 a topic in the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-developer-forum/pXgAlzzjkek/unsubscribe.

    To unsubscribe from this group and all its topics, send an email to erpnext-developer-forum+un…@googlegroups.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.

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

Thanks for reply. Yes, I am aware of importance of tab. Normally the system gives error if there is any issue with code indentation. I don't see any error in console. See below link for the gist code. I haven't used gist before so not sure what I have done below is correct or not.

https://gist.github.com/mayur-patel/6914969

PS: On server I don't see any support for custom_validate. I did grep for custom_validate on server but I didn't find anything except a mention of it in a readme file.

Kind regards,
MP

On Thursday, 10 October 2013 09:15:44 UTC+1, rushabh wrote:
Mayur - please post your code in gist / pastebin

the padding is important - the code must be padded by one tab.


W: https://erpnext.com
T: @rushabh_mehta

On 10-Oct-2013, at 1:44 PM, MP <ma...@gmail.com> wrote:




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.

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

HI Rushabh,

Thanks for reply. Yes, I am aware of importance of tab. Normally the system gives error if there is any issue with code indentation. I don't see any error in console. See below link for the gist code. I haven't used gist before so not sure what I have done below is correct or not.

https://gist.github.com/mayur-patel/6914969

Ok try this:


You need to indent with 2 spaces in custom script

we will fix this in the new release


PS: On server I don't see any support for custom_validate. I did grep for custom_validate on server but I didn't find anything except a mention of it in a readme file.

all events with prefix custom_ are called along with the main event i.e. custom_validate for validate

use webnotes.msgprint("") to be safe


Kind regards,
MP

On Thursday, 10 October 2013 09:15:44 UTC+1, rushabh wrote:
Mayur - please post your code in gist / pastebin

the padding is important - the code must be padded by one tab.


W: https://erpnext.com
T: @rushabh_mehta

On 10-Oct-2013, at 1:44 PM, MP <ma...@gmail.com> wrote:





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 a topic in the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-developer-forum/pXgAlzzjkek/unsubscribe.

    To unsubscribe from this group and all its topics, send an email to erpnext-developer-forum+un…@googlegroups.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.

    For more options, visit https://groups.google.com/groups/opt_out.
Thanks Rushabh and Nabin for helping in sorting this out. Much appreciated.

The script is working now. I have written couple of custom scripts (server side) in the past with tab. I will have to check those one to see if they are still working.

On the main subject, how do I access items information for the selected PO? Is there a method I can call similar to getchildren('Purchase Order Item',doc.name,'po_details');? I need to go through each line item to find their cost center and account information and from there I will find out related companies for these cost centers and account. Thanks.

Kind regards,
Mayur Patel

On Thursday, 10 October 2013 10:12:21 UTC+1, rushabh wrote:
Mayur,

HI Rushabh,

Thanks for reply. Yes, I am aware of importance of tab. Normally the system gives error if there is any issue with code indentation. I don't see any error in console. See below link for the gist code. I haven't used gist before so not sure what I have done below is correct or not.

https://gist.github.com/mayur-patel/6914969

Ok try this:


You need to indent with 2 spaces in custom script

we will fix this in the new release


PS: On server I don't see any support for custom_validate. I did grep for custom_validate on server but I didn't find anything except a mention of it in a readme file.

all events with prefix custom_ are called along with the main event i.e. custom_validate for validate

use webnotes.msgprint("") to be safe




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.

    For more options, visit https://groups.google.com/groups/opt_out.
for d in self.doclist.get({"parentfield": "po_details"}):
msgprint(d.item_code)

On 10-Oct-2013, at 4:12 PM, MP wrote:

Thanks Rushabh and Nabin for helping in sorting this out. Much appreciated.

The script is working now. I have written couple of custom scripts (server side) in the past with tab. I will have to check those one to see if they are still working.

On the main subject, how do I access items information for the selected PO? Is there a method I can call similar to getchildren('Purchase Order Item',doc.name,'po_details');? I need to go through each line item to find their cost center and account information and from there I will find out related companies for these cost centers and account. Thanks.

Kind regards,
Mayur Patel

On Thursday, 10 October 2013 10:12:21 UTC+1, rushabh wrote:
Mayur,

HI Rushabh,

Thanks for reply. Yes, I am aware of importance of tab. Normally the system gives error if there is any issue with code indentation. I don't see any error in console. See below link for the gist code. I haven't used gist before so not sure what I have done below is correct or not.

https://gist.github.com/mayur-patel/6914969

Ok try this:


You need to indent with 2 spaces in custom script

we will fix this in the new release


PS: On server I don't see any support for custom_validate. I did grep for custom_validate on server but I didn't find anything except a mention of it in a readme file.

all events with prefix custom_ are called along with the main event i.e. custom_validate for validate

use webnotes.msgprint("") to be safe





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.

    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.

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