Business Rule Error Message not working

Saib1
Tera Guru

Hi,

I have Business Rule and the error messgae is getting displayed eventhough i have filled the worknotes and update

When - Before

Condition - State changes to Assess

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

var leadTime = gs.getProperty('pan.bt.change.lead.time');

if(leadtime == 'true')

{

          if (current.work_notes == '') {
        gs.addErrorMessage('Change has been marked "Expedite", please provide the justification in Notes section.'); 
          /current.setAbortAction(true);
            current.state = previous.state;
            gs.setRedirect(current);
        } else
            current.u_expedite_change = true;
   }
})(current, previous);

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

try below,   

if (current.work_notes.getJournalEntry(1)=="") { //change this line
        gs.addErrorMessage('Change has been marked "Expedite", please provide the justification in Notes section.'); 
          /current.setAbortAction(true);
            current.state = previous.state;
            gs.setRedirect(current);
        } else
            current.u_expedite_change = true;

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

6 REPLIES 6

Pavankumar_1
Mega Patron

Hi,

it is not going to the loop because if(leadtime == 'true') typo error.

it should be if(leadTime == 'true') and remove  /on if loop

Note: for future reference all the variables that you declared on business rule will highlighted in blue color.

Script:

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

var leadTime = gs.getProperty('pan.bt.change.lead.time');

if(leadTime == 'true')

{

          if (current.work_notes.getJournalEntry(1) == '') { //use this if worknotes is Journal Inputt field type
        gs.addErrorMessage('Change has been marked "Expedite", please provide the justification in Notes section.'); 
          current.setAbortAction(true);
            current.state = previous.state;
            gs.setRedirect(current);
        } else
            current.u_expedite_change = true;
   }
})(current, previous);

Hope it Helps you!

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Ian Mildon
Tera Guru

Try with this edited version:

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

var leadTime = gs.getProperty('pan.bt.change.lead.time');

if(leadTime == 'true') {

    if (current.work_notes == '') {
        gs.addErrorMessage('Change has been marked "Expedite", please provide the justification in Notes section.'); 
            current.setAbortAction(true);
            current.state = previous.state;
            gs.setRedirect(current);
        } else {
            current.u_expedite_change = true;
        }         
   }
})(current, previous);

I also removed the single / on the abort action line as that would cause errors if left. However, if you are wanting to comment it out so it doesn't run, you need to insert //