Comments and Work Notes in Outbound PUT Rest API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 12:09 PM
Hi Team,
I'm trying to use a Business Rule that runs when I Update a record and Comment or Work Note changes. I want this script to pull the body of the last work note, and the body of the last comment. When I use a test string instead of current.comments.getJournalEntry(1) or current.work_notes.getJournalEntry(1), it executes correctly and adds the comment as expected to my external system (Jira).
I added ?sysparm_display_value=true to the end of my endpoint, but I am still not able to pull the last work note and journal entry.
Any ideas how to fix my business rule?
Here's the script I am currently using:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('Jira', 'addComment');
r.setStringParameterNoEscape('lastComment', current.comments.getJournalEntry(1));
r.setStringParameterNoEscape('lastWorkNote', current.work_notes.getJournalEntry(1));
r.setStringParameterNoEscape('issueKey', current.getValue('correlation_display'));
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 02:43 PM
Hi, I don't think that you would need to add anything to the 'endpoint' to ensure the update is triggered, as the target platform/endpoint is Jira? And I don't see anything obvious with the way you are referencing the last journal entries and the syntax tests OK in a PDI.
I assume this is an after update BR? Does it have any conditions? Have you added debugging to ensure that your BR is triggered?
If you are using the 'Post' button to commit your journal entries, then your updates are written directly to the journal and I don't believe that a BR on your task table would be triggered via a 'Post', whereas a Save\Update would trigger the task table BR; So depending on your requirements you may need to add an additional BR on sys_journal_field insert.
Perhaps you could clarify the requirement\trigger conditions and add some debugging\logging to your existing BR, so you can see when it is/isn't triggered and the journal entry content when it is triggered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 08:18 AM
Hi Tony,
Thanks for the response! I did add some debugging for my BR - when I enter test literal strings for both comment and work note, they are written to the appropriate Jira issue; it seems the issue lies in how I am trying to pull the last comment and last work note into their respective variables, but I just can't figure it out!
See below for script that sends test literal string for last comment and test literal string for work note to Jira appropriately when i add a comment or work note to an INC in SNOW:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('Jira', 'addComment');
r.setStringParameterNoEscape('lastComment', 'test literal string for last comment');
r.setStringParameterNoEscape('lastWorkNote', 'test literal string for work note');
r.setStringParameterNoEscape('issueKey', current.getValue('correlation_display'));
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 01:12 PM
Unfortunately your reply does not make the use case\process you are using clear.
If you add work_notes and\or comments and 'save' or 'update' the record, is your BR triggered?
What happens if you test using short_description change (or another field) as the trigger?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:01 PM
@jauntyjoe you able to solve the problem? I encountered the same issue. Please share your solution with me.
Thanks