Originally asked by Benjamin Kiene on 26 July 2021 (original question)
I’m trying to get the current value of a field of the issue I’m going to sync to in an incoming sync in ServiceNow, because I want to compare it with the value that is coming in from the other (source) side.
I tried to use incident.assigned_to, as this is what I would use to set the new value, so I thought it might contain the old value before that. But it seems to only work in one direction.
Is there any other way I can do that?
Comments:
Ariel Aguilar commented on 27 July 2021
Hi Benjamin,
It depends on the actual field type / name. For example, if you are syncing “Assignee” this should work:
if(entityType == "incident") {
incident.assigned_to = nodeHelper.getUserByEmail(replica.assignee?.email)?.key
}
Or you can receive a customField value as an example:
if(entityType == "incident") {
incident.assigned_to = replica.customFields."Jira Field Name"?.value
}
Kind regards,
Ariel
Benjamin Kiene commented on 06 August 2021
Thank you, Ariel, for your feedback, but maybe I wasn’t clear enough.
I wanted the current value of the destination before applying the source to it and it seems like
oldValue = incident.assigned_to
doesn’t do it.
The only idea that I could come up with is to use the nodeHelper.getReference function to get the current value of the destination record. Like so:
currentAssignedTo = nodeHelper.getReference("incident", "number", incidentNumer).assigned_to.value
newAssignedTo = nodeHelper.getUserByEmail(replica.assignee?.email)?.key
// Now I can do something like
if (currentAssignedTo != newAssignedTo) {
//do something here
}
I haven’t tested it yet, but I’m pretty sure that should work.
Or does anybody know a better way to get this current value of the destination?
Ariel Aguilar commented on 23 August 2021
Hi Ben,
This is good.
Kind regards,
Ariel