- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 05:54 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 06:07 AM
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
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 06:15 AM
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
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2022 06:29 AM
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 //