I want my sales team while filling project form, they can select the type of form and automatically the dynamic brief form opens for example; if the project type is graphic design the dynamic form is opened to select the details and select multi option from drop down in form.
Secondly, I want my production team can only preview project details but could not be able to change expect few fields how it can be done?
I want whole project form should be view and editibale to sales team but my production team should be able to view few relevant details such as my production team should not be able to set customer name and its sales thing but my sales person can see same goes with company selection; company can be select and change by sales person but production team should not be able to see it how it can be possible?
@Alizaintejani You can achieve what you want using a Client Script
that make changes to the form based on your needs…
For more information, read Form Script…
Thank you for your response. I am not a technical person here, can you guide me more on how can I do it as per my requirement mentioned?
@Alizaintejani I will be glad to help…
- Create a
Client Script
, choose the doctype you want to apply this script to and then selectForm
as the apply to target - Paste the following code and modify it as per your need
- Finally save the script and try it out
Don’t forget to read the comments within the code
// Replace the word "Doctype" with the name of your doctype
frappe.ui.form.on('Doctype', {
onload: function(frm) {
// Check if user has any of the roles
if (frappe.user.has_role(['Role Name1', 'Role Name2'])) {
// Make the fields read only
frm.toggle_enable(['fieldname1', 'fieldname2'], false);
// Or hide the fields
frm.toggle_display(['fieldname1', 'fieldname2'], false);
// Also you can show a message
frappe.msgprint({
title: 'Message Title',
message: 'Message Content',
indicator: 'blue',
});
// Or show a list in the message
frappe.msgprint({
title: 'Message Title',
message: ['Point 1', 'Point 2'],
indicator: 'blue',
as_list: true,
});
// Or show a table in the message
frappe.msgprint({
title: 'Message Title',
message: [
['Column 1', 'Column 2'],
['Column 1', 'Column 2'],
],
indicator: 'blue',
as_table: true,
});
}
}
});
I hope that I was helpful…
Hi,
Thank you for providing a solution. When I do it in the client script, it is giving me the error.
Any solution?
@Alizaintejani I can’t see what error you are referring to…
Can you please post a screenshot of the error or post the exact message of the error so I can help…
I have figured it out. Its done
Thanks
I got stuck again, in the script, i write a role in user to function this… but it is applicable to administrator too how to solve this now…
I write in user “Production team” but it got applicable to administrator too, I as administrator can only view and project type got hide from admin as well
Do you want to restrict some fields from Administrator
role also, or you want the Administrator
role to bypass all the restrictions you made for other roles?
If you want to do any of the above, then do something like the following…
// Replace the word "Doctype" with the name of your doctype
frappe.ui.form.on('Doctype', {
onload: function(frm) {
// Start with checking for Administrator role
if (frappe.user.has_role('Administrator')) {
// Restrict whatever you want here or just skip this step
// Use "return" to end the code immediately
return;
}
// Continue with the other roles check and restrictions
}
});
Hi,
Thanks for responding. I tried your coding but its same issue here the restriction I applied on other user is applied to Administrator too.
I want " Administrator
role to bypass all the restrictions you made for other roles"
Also, please guide me do I need to create new client script or I have to do in the same one is create?
@Alizaintejani Just edit the current client script…
The Administrator
role check must be at the top of the onload
method…
// Replace the word "Doctype" with the name of your doctype
frappe.ui.form.on('Doctype', {
onload: function(frm) {
// The following check must be at the top
if (frappe.session.user === 'Administrator' || frappe.user.has_role('Administrator')) return;
// Put the rest of your role checks here
}
});
Thank you
@kid1194 i need your help again, the above script is working fine, the problem is when I checkbox “only if creator” in role permission because I want user to view only assigned task not all, so the user is unable to make changes in form like change status edit project name etc.
is there anything to do custom scripting?
Can you please help?
@Alizaintejani Sorry about the late reply…
I think that my Better List View plugin can help…
I’m not sure if it will work…
Just give it a try, the plugin and the code below…
frappe.listview_settings['Task'] = {
query_fields: ['tabToDo.allocated_to'],
query_filters: [
['tabToDo.reference_type', '=', 'Task'],
['tabToDo.reference_name', '=', 'tabTask.name'],
['tabToDo.status', '!=', 'Cancelled'],
['tabToDo.allocated_to', '=', frappe.session.user],
]
};