- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 11:56 PM
Only persons with problem manager role should be able to create problem tasks , when persons with other role opens the Form it should throw error on load
Please note we don't want to write ACL we want to control this by using onload client script
@DevE @Chaitanya5 @problemmgmt @itsm
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 12:09 AM
Hi @VijayKummamuru,
for throwing error message on load of the form you can use
function onLoad() {
//Type appropriate comment here, and begin script below
if (!g_user.hasRole('problem_manager')) {
g_form.addErrorMessage('only users with problem_manager are allowed to create problem task');
}
}
but the user will still be able to create the problem tasks
if you don't want them to create
create a before insert BR also with below script
if (!gs.hasRole('problem_manager')) {
gs.addErrorMessage('only users with problem_manager are allowed to create problem task');
current.setAbortAction(true);
}
it's better to achieve this throw ACL but since you don't want acl you can go with this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 03:23 AM
best way is to handle using ACL at table level
use this for onLoad client script, remember the user can still see the fields as readonly but can submit, so you will require onSubmit script as well
function onLoad() {
if (!g_user.hasRoleExactly('problem_manager')) {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}
onSubmit:
function onSubmit() {
if (!g_user.hasRoleExactly('problem_manager') && g_form.isNewRecord()) {
g_form.addErrorMessage('Only problem manager can submit');
return false;
}
}
You can also use Before insert business rule
if (!gs.hasRole('problem_manager')) {
gs.addErrorMessage('Only problem manager can submit a new record');
current.setAbortAction(true);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 12:09 AM
Hi @VijayKummamuru,
for throwing error message on load of the form you can use
function onLoad() {
//Type appropriate comment here, and begin script below
if (!g_user.hasRole('problem_manager')) {
g_form.addErrorMessage('only users with problem_manager are allowed to create problem task');
}
}
but the user will still be able to create the problem tasks
if you don't want them to create
create a before insert BR also with below script
if (!gs.hasRole('problem_manager')) {
gs.addErrorMessage('only users with problem_manager are allowed to create problem task');
current.setAbortAction(true);
}
it's better to achieve this throw ACL but since you don't want acl you can go with this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 02:20 AM
Thanks @Chaitanya ILCR , is there any way we can make form read-only in onload client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 03:23 AM
best way is to handle using ACL at table level
use this for onLoad client script, remember the user can still see the fields as readonly but can submit, so you will require onSubmit script as well
function onLoad() {
if (!g_user.hasRoleExactly('problem_manager')) {
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
}
}
onSubmit:
function onSubmit() {
if (!g_user.hasRoleExactly('problem_manager') && g_form.isNewRecord()) {
g_form.addErrorMessage('Only problem manager can submit');
return false;
}
}
You can also use Before insert business rule
if (!gs.hasRole('problem_manager')) {
gs.addErrorMessage('Only problem manager can submit a new record');
current.setAbortAction(true);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader