Correct my code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi
I have a requirement where in i have to create a field named compliant in problem task and that field should be read only (this is done) and that should display Yes if the task is closed date is less than due date, and No the other way round.
I tried to achieve this via BR, and i am not getting the proper results.
Can you please correct me on what i did wrong.
Thanks
Code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
this code is not populating anything in my field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Considering your business rule is before Insert/update and the field name and choice value Yes, No are correct
This code should work
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var closed_date_str = new GlideDateTime(current.getValue('closed_at'));
var due_date_str = new GlideDateTime(current.getValue('due_date'));
if (due_date.getNumericValue() > closed_date_str.getNumericValue()) {
current.setValue('u_compliant', "Yes");
} else {
current.setValue('u_compliant', "No");
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
i tried the negative scenario to reflect the compliant as No still i am getting as Yes, even though i set the due date as past value and i close it now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
@Ankur Bawiskar please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
so what debugging did you do?
what logs you added and what are your findings?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader