Sync of custom fields from Azure to ServiceNow and vice versa

Originally asked by Naveen Negi on 09 March 2021 (original question)


I have been trying to sync a custom field created on ServiceNow end with a custom field on Azure end but with no luck. The name of the field is CR number(ServiceNow end ) and CR Number(Azure end) Below is the code I have using on both the side:

ServiceNow

Outgoing:

replica.customFields.“CR Number” = entity.customFields.“CR number”

Incoming:

entity.customFields.“CR number”?.value = replica.customFields.“CR Number”.value

Azure:

Outgoing:

replica.customFields.“CR number” = workItem.customKeys.“CR Number”

Incoming:

workItem.customKeys.“CR Number”?.value = replica.customFields.“CR number”?.value

Below is the error which I am getting:

com.exalate.api.exception.script.ScriptException: Cannot get property ‘value’ on null object at com.exalate.error.services.ScriptExceptionCategoryService.categorizeProcessorAndIssueTrackerExceptionsIntoScriptExceptions(ScriptExceptionCategoryService.scala:32) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:47) at com.exalate.replication.services.processor.CreateIssueProcessor.$anonfun$executeScriptRules$1(CreateIssueProcessor.scala:103) at scala.util.Try$.apply(Try.scala:213) at com.exalate.replication.services.processor.CreateIssueProcessor.executeScriptRules(CreateIssueProcessor.scala:100) at com.exalate.replication.services.processor.CreateIssueProcessor.createIssue(CreateIssueProcessor.scala:77) at com.exalate.replication.services.replication.request.CreateIssueSyncRequestState.transition(CreateIssueSyncRequestState.scala:36)


Answer by Francis Martens (Exalate) on 10 March 2021

The serviceNow incoming in your incoming

entity.customFields."CR number"?.value = replica.customFields."CR Number".value

The error you encounter is

Cannot get property ‘value’ on null object

Probably the ‘replica.customFields.“CR Number”’ resolves to null, and the expression is not protected with the groovy safe navigation operator (the ?)
You can inspect the content of the replica in the error details → remote replica

If this shows to be true, find out why it is null