- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 07:28 AM
Hi,
I want to Prevent users from closing RITM if any of its TASK is still open.
Any help is highly appreciated.
Thanks,
Aamir
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 08:51 AM
Hi Aamir,
you are right, I missed it, you have to set the state to the previous value as well:
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.addActiveQuery();
task.query();
if(task.hasNext()){
gs.addErrorMessage('Please, close all Tasks before to close the Request Item');
current.state = 2;
}
Regards,
Valentina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2018 09:51 AM
I am trying this BR.
Both current.state = 2; and current.state = previous.state; are not working. The state on the requested item remains "Closed complete." Have you experienced this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2018 10:32 AM
I solved this by doing a current.active = true; before the current.state = previous.state;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2018 02:56 PM
Hi Valentina,
I've got this script working for me too, but the error message displays more than once.
gs.addErrorMessage('Please, close all Tasks before to close the Request Item');
Any idea how/where I add a hideFieldMsg in the script so that the error message only displays once?
Many thanks,
Anna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2017 07:50 AM
just because there is already a business rule that runs to close RITM when all its TASKS are closed, so you dont need to worry about this .
NOW- before that if you want users to prevent from closing , you may run a client script ON LOAD
if(g_user.hasRole() != 'admin') // check that if loggedin user is NOT Admin , then set fireld to readonly else revoke
{
g_form.setReadOnly('state', 1);
}
if(g_user.hasRole() == 'admin')
{
g_form.setReadOnly('state', 0);
}