Alert in Business rule

Naresh Damji
Tera Expert

Hi All,

I am having issue where i want to throw alert to user in business rule. Currently my business rule is running on sys_attachment table. The condition is like below :

find_real_file.png

The code is like below which checks if the file size is greater than certain limit :

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

var i = parseInt(current.size_bytes);
gs.addErrorMessage('i is' + i);

if(i > 10)
{

current.setAbortAction(true);
gs.log('-=--------------------------i is' + i);
gs.addInfoMessage("File Size is too large");

}

})(current, previous);

All other script work but none of the gs.addInfoMessage() functions are working. I can able to see the log message and action is getting aborted as per script just needed the alert message throw to user.

I have tired various solution provided in community and forum but none of them worked.

Can someone please help on this case

Regards,

Naresh

1 ACCEPTED SOLUTION

Naresh Damji
Tera Expert

Just to update on this, I have achieved this by adding some code in UI page which helped me to restrict based on image size.

View solution in original post

13 REPLIES 13

Hi BeBold,

BRs is in Global scope.

Anurag Tripathi
Mega Patron
Mega Patron

Hi Naresh

Use this in a business rule.. Tried and tested

var msg='haha';

gs.addErrorMessage('<script>var t=setTimeout(function(){var test = confirm("' + msg + '");if(!test){return false;}},500);</script>' + msg);

-Anurag

Hi Anurag,

I have also tried this but didnt worked. btw i am on Kingston instance.

Paul Curwen
Giga Sage

HI,

 

I've never used a gs.addinfomessage after setAbortAction(true). I've not even previously considered if that is an issue, interesting. Just try this, should do the trick:

 

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

var i = parseInt(current.size_bytes);
gs.addErrorMessage('i is' + i);

if(i > 10)
{

 

gs.log('-=--------------------------i is' + i);


gs.addInfoMessage("File Size is too large");

current.setAbortAction(true);

gs.setRedirect(current);

}

})(current, previous);

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Hi Paul,

 

Somehow that did worked partly.. When i am trying to upload attachment in incident form the alert is coming to other tab on which same instance of servicenow is opened. This seems strange.

Also the upload process seems to be getting stuck in progress with progress bar keep running.

 

Thanks