Make variables read only after group approval stage (RITM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 09:37 AM
Hello folks,
I have created a Script include and Client script to make 2 variables editable after user submit, so the approval team can make changes and assign a better group team to work, it's all working fine so far, the problem now is, those variables still editable even after the approval stage is Approved, I have tried some variations here but still not finding a solution, below is the client script I'm using, could you please help me this situation?
function onLoad() {
//Type appropriate comment here, and begin script below
var number = g_form.getValue('number');
var ga = new GlideAjax('XXXXXXXX');
ga.addParam('sysparm_name', 'fetchDataweb');
ga.addParam('sysparm_name_number', number);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == 'Client XXXX') {
g_form.setReadOnly('target_date', false);
g_form.setReadOnly('all_assin_group',false);
g_form.setMandatory('all_assin_group', true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 10:18 AM
I think a simpler way to accomplish this would be to use a UI Policy. You can add script in there if needed and check the value of the "stage" field and determine whether to allow the variable(s) to be editable or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 10:30 AM
Add some more conditions in the client script to validate approval stage. If approval stage == approved don't call the script include from the client script.
If it is not possible to validate approval stage in client you can alternatively add the validation condition in the script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 07:00 PM
you can add condition for state on approval record on your table
your client script is on which table?
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
12-27-2024 09:16 AM
The table is Sc_req_item.
I was able to change the script and now it is read only again after approval.
Now I have another issue, the variable Assignment Group is mandatory, but if the approver goes to service portal and click approve, it is approving even with that field empty, do you know how can I prevent the user to approve when that field is not populated?