Select default Leave Approver

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur

You can use user properties

Go to setup > profile > desires profile. Click on user properties button and add a user property "leave_approver" with value as the manager's user id. 

I think it should work. 

Sent from my phone

On 08-Mar-2013, at 6:02 PM, MP <ma...@gmail.com> wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/__8WIcAaaEwJ.

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

 

 

Mayur, 

you can query the manager using a query to "webnotes.client.get_value" (see custom script example).

And if the returned value is present in the options (cur_frm.get_field("leave_approver").df.options) then you can use cur_frm.set_value("leave_approver", value) to set the value in the form.

You will have to piece these together from examples on the client script wiki page.

Also please post your solution here.

best,
Rushabh


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

On 11-Mar-2013, at 3:11 PM, MP <ma...@gmail.com> wrote:



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur




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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/__8WIcAaaEwJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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

 

 

Hi Anand,

Under Property drop-down list, there is no option for leave_approver. Is it possible to create new property called leave_approver? if not, how do we handle my issue?

Mayur

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/QEnIeFRy1MgJ.

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

 

 

Hi Rushabh,

I am stuck and need a little bit of help here.

I am trying to get the User_id of an employee who is a manager of selected employee. Using “webnotes.client.get_value” I can get the Reports_to detail for selected employee but how do I get the user_id of the Report_to employee? Do I need to call webnotes.client.get_value method twice. Any help will be appreciated. Thank.

Mayur

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/SCgj3G_KZWgJ.

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

 

 

Hi Mayur,

A simpler solution would be to write add fetch on Reports To so that the report to user's profile is fetched for the underling.

Then, use get_value only once to fetch the reports_to_id :)

Thanks,
Anand.

On 19-Mar-2013, at 5:54 PM, MP <ma...@gmail.com> wrote:

Hi Rushabh,

I am stuck and need a little bit of help here.

I am trying to get the User_id of an employee who is a manager of selected employee. Using "webnotes.client.get_value" I can get the Reports_to detail for selected employee but how do I get the user_id of the Report_to employee? Do I need to call webnotes.client.get_value method twice. Any help will be appreciated. Thank.

Mayur

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur




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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/SCgj3G_KZWgJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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

 

 


Hi Anand,

What do you mean by add fetch on report_to. Is there any function called add_fetch that I can call?

Mayur
On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/DCTTwH1LkIoJ.

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

 

 

Sorry for causing confusion. Here is the link:
https://github.com/webnotes/wnframework/wiki/Client-side-scripting#using-add_fetch-to-pull-link-details

Adding this script will cause a field in a linked document to be fetched, when a link field value is updated.

So, in employee form, you can set:
cur_frm.add_fetch('employee','user_id','reports_to_user_id')
reports_to_user_id being a custom field.

This will save the user id of the reporting manager in the employee's form.

Now you only need to use get_value once for the leave application page and get reports_to_user_id :)

Thanks,
Anand.



On 19-Mar-2013, at 6:08 PM, MP <ma...@gmail.com> wrote:


Hi Anand,

What do you mean by add fetch on report_to. Is there any function called add_fetch that I can call?

Mayur
On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur




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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/DCTTwH1LkIoJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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

 

 

Hi Anand,

I am sorry if I am taking lot of your time but it didn’t work. This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified employee.js file and added a new line for cur_frm.add_fetch(‘employee’,‘user_id’,‘reports_to_user_id’)
- After that I clicked on Tools –> Clear Cache & Refresh
- Then I clicked on HR–> Employee –> one of the employee
- Selected an employee as  Reports To.
- clicked save.
- i checked the value for reports_to_user_id in database and also in web using web console and it is showing null.

Am I missing something?

regards,
Mayur Patel

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/MQ3ITAClgjkJ.

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

 

 

Mayur,

You have to add the add_fetch method in Custom Script the target doctype (Leave Application) not source

In add_fetch (https://github.com/webnotes/wnframework/wiki/Client-side-scripting#using-add_fetch-to-pull-link-details)

Also, the sequence of parameters is link, source, target

So it should be:

cur_frm.add_fetch('employee', 'reports_to_user_id', 'user_id')

best,
Rushabh


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

On 20-Mar-2013, at 4:08 PM, MP <ma...@gmail.com> wrote:

Hi Anand,

I am sorry if I am taking lot of your time but it didn't work. This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified employee.js file and added a new line for cur_frm.add_fetch('employee','user_id','reports_to_user_id')
- After that I clicked on Tools --> Clear Cache & Refresh
- Then I clicked on HR--> Employee --> one of the employee
- Selected an employee as  Reports To.
- clicked save.
- i checked the value for reports_to_user_id in database and also in web using web console and it is showing null.

Am I missing something?

regards,
Mayur Patel

On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur




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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/MQ3ITAClgjkJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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

 

 

Hi Rushabh,

This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified leave_application.js file and added a new line for cur_frm.add_fetch(‘employee’,‘reports_to_user_id’,‘user_id’)

- After that I clicked on Tools –> Clear Cache & Refresh
- when i tries to access cur_frm.doc.user_id or cur_frm.doc.reports_to_user_id it is coming as undefined.

How do reports_to_user_id suppose to get populated in the database?

I don’t think I really understand how this is suppose to work.

regards,
Mayur Patel



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur



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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/qs8_WfiCQOEJ.

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

 

 

Mayur,

add_fetch is a javascript function and will only work on change of the employee field in the Leave Application form.

I think the problem for you is that the employee field is auto-selected (by default) so the change trigger may not work... Let me see if we can fix this for new forms. Can you confirm if it works when you change the employee value?

For older records, you will have to write a database (update) query.

Another (more elegant) solution is that in the employee.py,, just add a new default called "reports_to" so where-ever the reports to field is there in the form, it will auto-update by defaults... (https://github.com/webnotes/erpnext/blob/master/hr/doctype/employee/employee.py#L70). 
This way you can also use in other forms like Expense Claim for example.

best,
Rushabh


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

On 20-Mar-2013, at 4:40 PM, MP <ma...@gmail.com> wrote:

Hi Rushabh,

This is what I did:

- Using web interface I  added a custom field called reports_to_user_id (FieldName) for Employee doctype.
- On server, I modified leave_application.js file and added a new line for cur_frm.add_fetch('employee','reports_to_user_id','user_id')
- After that I clicked on Tools --> Clear Cache & Refresh
- when i tries to access cur_frm.doc.user_id or cur_frm.doc.reports_to_user_id it is coming as undefined.

How do reports_to_user_id suppose to get populated in the database?

I don't think I really understand how this is suppose to work.

regards,
Mayur Patel



On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?


Mayur




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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/qs8_WfiCQOEJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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

 

 

Hi Rushabh,

I am logged in as Administrator. So by default, employee is not selected. But it still doesn’t work when I select an employee. So basically it is not working. One thing I forgot to mention that reports_to_user_id is defined as Hidden field for employee doctype. Not sure if this matters?

I can update the old records manually but I am interested in knowing how the value for reports_to_user_id will get populated in the database?

As per your suggestion about elegant solution, are you saying that I need to add webnotes.conn.set_default(“reports_to”, self.doc.report_to, self.doc.user_id in def update_user_default(self): of employee.py? what does this do?

Mayur


On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,

On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?




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 post to this group, send email to er...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/l5RF_Rtw5fEJ.

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

 

 

Mayur,

Hi Rushabh,

I am logged in as Administrator. So by default, employee is not selected. But it still doesn't work when I select an employee. So basically it is not working.

Do you see anything in your error console? Is the employee name getting selected?

One thing I forgot to mention that reports_to_user_id is defined as Hidden field for employee doctype. Not sure if this matters?

Should not matter

I can update the old records manually but I am interested in knowing how the value for reports_to_user_id will get populated in the database?

Just as employee name is set when employee is selected.

As per your suggestion about elegant solution, are you saying that I need to add webnotes.conn.set_default("reports_to", self.doc.report_to, self.doc.user_id in def update_user_default(self): of employee.py? what does this do?

Yes this will make a "default value" for "reports_to" -- so where "reports_to" field appears, this will be set as the value. I would recommend this solution.

Mayur


On Friday, March 8, 2013 11:32:17 PM UTC+11, MP wrote:

Hi,


On Leave Application page, we would like the name of the selected employee’s immediate manager (Report To field from employee) to be selected by default if it is one of the option in the drop-down list of Leave Approver. For example if x is manager of y and if x is a leave approver, when y is selected as Employee on Leave application page, we want system to select x as default on Leave application page for Leave Approver drop-down. How can we achieve this?





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 post to this group, send email to er…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/l5RF_Rtw5fEJ.

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

 

 




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 post to this group, send email to er...@googlegroups.com.

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