- 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:20 PM - edited 07-29-2024 12:21 PM
Hello @TheKatherine ,
I have reviewed your code snippet and I want to suggest you few things.
You do not need to create a new field on any table (e.g. problem) to fetch the value of work_notes field. Work notes field itself is a journal type field which stores all its values for a given table record (irrespective of time period) in Journal Entry [sys_journal_field] table.
To solve above problem statement, there are two ways -
1. Either you write a business rule on problem table and fetch the latest entry of work_notes from journal entry table.
2. OR you fetch the value of work_notes field using these functions -
getJournalEntry(1) Gives you the most recent entry
getJournalEntry(-1) Gives you all entries
Let me know if it helps.
Mark this as Accepted Solution/Helpful if applicable.
Regards,
Shubham
- 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:45 PM - edited 07-29-2024 12:53 PM
Based on GlideElement API documentation, I think it should be getJournalEntry(1) rather than getJournalEntry(0).
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:30 AM
Thank you for the help.