ServiceNow to PagerDuty Integration - Cannot set Incident Work Notes using Inbound Field Rules (IFRs)

Just as the title states, I’m trying to map incoming data to create a Work Note entry but am having no luck doing so.

Context:
PagerDuty webhook type: trigger
Type: Set from PagerDuty webook payload
ServiceNow Incident field: Work Notes
Run lookup script: checked

The code I’m using for the lookup script is below:
var details = JSON.stringify(value, null, 2);
result = details;

The ‘value’ variable contains a JSON object that needs to be serialized so that it can be printed. If it’s not serialized, it will return ‘Object object’.

I’ve confirmed that the payload data is passing through the variables successfully by setting the ‘ServiceNow Incident Filed’ to ‘Description’. The data shows up there no problem when a test ticket is created. But when I try to map it to ‘Work Notes’, no work notes are created.

Any help on this issue is greatly appreciated.

Hi Julian,

Unfortunately work notes cannot at this time be added via Inbound Field Rules, so the script include PagerDutyInboundCustomScript must be used instead (in cases like this where inbound field rules are not suitable/possible, this script is the recommended location for customizations to the PagerDuty ➔ ServiceNow flow direction).

A common use case is the desire for custom details (which are visible on PagerDuty alerts/incidents that are created via the Events API by monitoring tools) to be made visible on the subsequently created ServiceNow incident. I’ll use that case as an example to illustrate how to leverage PagerDutyInboundCustomScript instead of Inbound Field Rules to create an automated work note. (NOTE: this steps below will only work for incidents that originate in PagerDuty and subsequently create a linked ServiceNow incident, i.e., with a flow of monitoring tool / Events API ➔ PagerDuty ➔ ServiceNow).

Adding a block of code similar to the following example to PagerDutyInboundCustomScript (which is located in ServiceNow under PagerDuty ➔ Configuration ➔ Configuration files ➔ Script Includes (tab)) inside the customPostTransformActivity function - and somewhere below the first if (source.message_type block - will add all custom details (when extant) to the ServiceNow incident as a work note:

    else if (source.message_type == "incident.trigger") {
      var payload = JSON.parse(source.payload);
      if (payload.log_entries[0].channel.hasOwnProperty('details')) {
        target.work_notes = payload.log_entries[0].channel.details;
      }
    }

If you run into any issues with implementation, feel free to reach out to us at support@pagerduty.com - we’d be happy to take a closer look.

The above is accurate as of v7.6 of the PagerDuty app for ServiceNow on Rome.

2 Likes

Thanks a bunch! This worked just as I had expected.

Hi Julian,

Tagging in here for Ehler, happy to hear it sounds you have things under control. Please let us know if we can be of further asstance!

1 Like