Client Script on Salary Slip

I have a client script that runs perfectly well if i create and save a salary slip directly from salary slip. However, when salary slip is created from payroll entry this script is not run. Any help with it plz?

frappe.ui.form.on(‘Salary Slip’, ‘after_save’, function(frm, cdt, cdn)
doctype:‘Lunch Mess’,
if(r.message !== undefined){

Client scripts are triggered only when you interact with the doc through the UI as it runs on the client side (browser). As you’re creating the Salary Slip from the Payroll Entry, the client script won’t work.

You should try achieving this with a server script instead.

Thanks. Would the same scrip / code work in server script?

1 Like

Just try it
it should work but you will not know, until you try

Tried; it doesn’t work.
I just need to fetch data from one doctype to salary slip for each employee.


Client script is written in Javascript, whereas Server Script runs on Python.


1 Like

@usmanalikhan - If I am able to understand it correct, you have a custom doctype ‘Lunch Mess’ and it stores opt_in for employees. You would like to set the opt_in in salary slip from this custom doctype matching the employee.

You can create a server script for Salary Slip Doctype on Before Validate with the code below:
doc.opt_in = frappe.db.get_value(‘Lunch Mess’, {‘employee’ : doc.employee}, ‘opt_in’)

I am unaware of your use case, here are my comments.
You do not need a custom doctype, a custom field in Employee doctype would also have sufficed. Alternatively, you can also add it to the salary structure assignment doctype. The benefit of this approach is that you can use the lunch mess as a condition in the salary component.


Thank you @atulagrawal . This code worked perfectly!

Just to add to the use case: the reason I created a custom doctype was that this allows individual employees access to choose whether to opt-in or opt-out of lunch mess for a particular month. We dont want employees to be able to edit employee data and adding it as a salary component would also not allow the flexibility for employees to change their option for the month, if they so wish.

Thanks a lot again for your help!