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

this was helpful


but the state is not setting to previous state after i used "current.state=previous.state" also.



can you please help me with this also how to set the state value to previous state value.


Hi Naveen,



You do not have to use "current.state=previous.state". Did you try the script which I have provided in my last response? If not, please use the same. Whilst you will reload the record form after getting the addInfoMessage, you will find the record with it's last state (before selecting the 'Closed' state) automatically. Also please note that the Business rule will be of Before Update type.


I have checked that in my instance and is working fine. Please let me know if you find any issue.



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


yes i have used it


after that also i ma ot setting the state to previous state on the form but int he list view it is not showing as closed/resolved.



find_real_file.png


Hi Naveen,



You have basically achieved your requirement. Request you to reload the form once you find the error as you have shown in your last response. You can see that the record is not updated neither is Closed/Resolved.



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


Hi ursnani,



Did you able to have a look at my last response?


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.


If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review   How to Mark Answers Correct From Inbox View