- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 10:44 AM
Any help on Business Rules is greatly appreciated.
I would like to create a Business Rule to capture the last entry of worknotes from a Problem ticket using a Business Rule (on update or insert)and then be able to take the results and show it on a report.
In searching, I found the following code for a business rule ... is this accurate?
Do I need to create the new field (u_latestupdate) on the Problem table first? Would it be a string field?
business rule code:
(function executeRule(current, previous /*null when async*/ ) {
current.u_lastestupdate = current.work_notes.getJournalEntry(1);
current.setWorkflow(false);
current.update();
})(current, previous);
thank you
TheKatherine
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 12:33 PM - edited 07-29-2024 12:50 PM
Yes, a custom string field (u_latestupdate) is required to store the latest work note entry. Without this field, you won't have a place to save and display the most recent work note entry on the Problem ticket.
Create the field first, then use the Business Rule to populate it. Once set up, you can use the field for reporting purposes.
(function executeRule(current, previous /*null when async*/) {
// Get the latest work note entry
var latestEntry = current.work_notes.getJournalEntry(1);
if (latestEntry) {
current.u_latestupdate = latestEntry;
}
})(current, previous);
Happy Learning
…………………………………………..
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 12:48 PM - edited 07-29-2024 12:51 PM
If you want just the last work note, then your approach is correct and the code also looks good, assuming that you are going to use an "after update" business rule. In case of a "before update" business rule, you don't need current.update() at all. A "before" business rule is preferable in such cases, but it may not work in your particular case because Work Notes is a journal field and is stored separately from the main record. But you can still give it a try.
Alternatively, you could simply add Work Notes as a column to your list report and do without any business rules.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/