Need help hiding status options

Conan_Lloyd
Mega Expert

I am trying to figure out how to hide some of my status items on a request item until all related tasks are closed. I reied simply hiding the options but then my Request Items would not auto close when the tasks closed.

Below is my fumbling attempt:

// Hide "Closed" Incident state from everyone but itil_admin

function onLoad() {

var optsk = new GlideRecord('task');
optsk .addQuery('request_item','number');
optsk .addQuery('state', optsk.state<4);
optsk .query();
while (optsk .next()) {
           g_form.removeOption('state', 4);
           g_form.removeOption('state', 7);
           g_form.removeOption('state', 10);
           g_form.removeOption('state', 11);
 }
 }


The basic premise is that we don't want folk to close request items manually. We have a rule that closes them automatically when the tasks are all closed. My perfect world would be a simple rule that prevents closing a request item if there are any open tasks.
1 ACCEPTED SOLUTION

Here is what we did for our Problem table to prevent problem closure if there were any active tasks.   We created a business rule with the following conditions:



  • Source Table = Problem
  • Order = 10
  • Active = Checked
  • When = Before
  • Insert and Update = checked
  • Condition =
    current.state == 7
  • Script = =

//Query for associated active tasks  


//Should be run as a 'before' business rule on the change_request table  


var rec = new GlideRecord('problem_task');  


rec.addQuery('problem', current.sys_id);  


rec.addQuery('active', true);


rec.query();  


//If any of the tasks are active abort the submission  


if(rec.hasNext()){  


    gs.addInfoMessage('All Problem Tasks must be closed prior to closing the Problem');  


    current.setAbortAction(true);


}




Hope this helps you



~Conan


View solution in original post

7 REPLIES 7

Jace Benson
Mega Sage

Why not just make the field read-only?


Conan_Lloyd
Mega Expert

The techs need to be able to mark things to Work in progress, pending, or pending change. We just don't want them to be able to choose close complete, close incomplete, etc


Conan_Lloyd
Mega Expert

Nevermind, I managed to get a different solution in here. Thanks anyway.


Hi Conan,


I am trying to do the same. Where I would like to prevent closing the request if tasks are open.  



Are you able to share where you found this solution.



Many Thanks,


Shoaib