Problem should not close unless the problem task is closed

ursnani
Giga Guru

Can you please help me with this.

The problem should not be closed/resolved unless the problem task is closed.

i had written a before business rule(update)

(function executeRule(current, previous /*null when async*/) {

      var gr = new GlideRecord('problem_task');

gr.addQuery('active','true');

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

gr.query();

if (gr.next()) {

current.setAbortAction(true);

}

})(current, previous);

though i am getting the message as invalid update but the state is changing to Closed/Resolved.

and also i want to display an alert message for the user saying that problem task is not closed.

Can anyone please help me.

Thanks

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi Naveen,



The Script you have written is perfectly fine, I believe. Please try to reload the form when the 'Invalid Update' comes up. Because the form is not saved and it remains the previous state actually.


Also from Server Side Script you can not use alert message, but you can use AddInfoMessage (for details Scripting Alert, Info, and Error Messages - ServiceNow Wiki). Please use the below script:




(function executeRule(current, previous /*null when async*/) {



  var gr = new GlideRecord('problem_task');


  gr.addActiveQuery();


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


  gr.query();


  if (gr.next()) {


  gs.addInfoMessage('Please close the related Problem tasks first.');


  current.setAbortAction(true);


  }


})(current, previous);



I hope this helps.Please mark correct/helpful based on impact


View solution in original post

12 REPLIES 12

SAP1
Kilo Contributor

Hi,

I have check with above code and its working properly but I am facing with "Invalide Update" pop up.

Please suggest.

 

Thanks,

Snehal.

SAP1
Kilo Contributor

Hello All,

I am facing with "Invalid Update" popup message.

Please suggest me.

Thanks,

Snehal.

HI SAP,

 

What is the issue you are facing ?