- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello All
If āRequested Forā rolls up to the following managerās: allow the user to continue updating the form.
- Abel tuter
- ALexnder
- Ajay chandra
If not, donāt allow the user to update form and pop-up below error message:
āYou are not eligible to submit this request, please read the message at top of the formā
Script include
please validate script and provide the suggestions please
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @bhanukota09
1. Just try with Onchange Client script:
- Type: onChange
- Variable: requested_for
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') return; var ga = new GlideAjax('ValidateRequestedForManager'); ga.addParam('sysparm_name', 'checkManager'); ga.addParam('sysparm_req_for', newValue); ga.getXMLAnswer(function(answer) { if (answer !== 'true') { alert("You are not eligible to submit this request, please read the message at top of the form"); g_form.clearValue('requested_for'); } }); }
2. Create a script include
- Navigate to System Definition > Script Includes and click New.
- Name: ValidateRequestedForManager
- Client callable: Check the box
var ValidateRequestedForManager = Class.create(); ValidateRequestedForManager.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkManager: function() { var reqFor = this.getParameter('sysparm_req_for'); if (!reqFor) return 'false'; var allowedManagers = ['<sys_id_1>', '<sys_id_2>', '<sys_id_3>']; // Replace with actual sys_ids for Abel, Alexander, Ajay var user = new GlideRecord('sys_user'); if (user.get(reqFor) && allowedManagers.indexOf(user.manager.toString()) > -1) { return 'true'; } return 'false'; }, type: 'ValidateRequestedForManager'});
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why not do this validation using onChange and show error message near that field/variable?
Don't use onSubmit for this
š” If my response helped, please mark it as correct ā and close the thread šā this helps future readers find the solution faster! š
Ankur
⨠Certified Technical Architect || ⨠10x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
My field in the variable set, suppose I'm using on change, is unable to select a variable, right?
There is no error showing,just take time for submission. It's checking the manager hierarchy. I need an immediate response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @bhanukota09
1. Just try with Onchange Client script:
- Type: onChange
- Variable: requested_for
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') return; var ga = new GlideAjax('ValidateRequestedForManager'); ga.addParam('sysparm_name', 'checkManager'); ga.addParam('sysparm_req_for', newValue); ga.getXMLAnswer(function(answer) { if (answer !== 'true') { alert("You are not eligible to submit this request, please read the message at top of the form"); g_form.clearValue('requested_for'); } }); }
2. Create a script include
- Navigate to System Definition > Script Includes and click New.
- Name: ValidateRequestedForManager
- Client callable: Check the box
var ValidateRequestedForManager = Class.create(); ValidateRequestedForManager.prototype = Object.extendsObject(AbstractAjaxProcessor, { checkManager: function() { var reqFor = this.getParameter('sysparm_req_for'); if (!reqFor) return 'false'; var allowedManagers = ['<sys_id_1>', '<sys_id_2>', '<sys_id_3>']; // Replace with actual sys_ids for Abel, Alexander, Ajay var user = new GlideRecord('sys_user'); if (user.get(reqFor) && allowedManagers.indexOf(user.manager.toString()) > -1) { return 'true'; } return 'false'; }, type: 'ValidateRequestedForManager'});
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti