Skip the sync

Originally asked by Rebecca Love on 05 July 2023 (original question)


I have an incoming sync error on a ServiceNow node. It looks like to resolve this, the script needs to end if the state of the target record is “Closed”. So far, I’ve not successfully scripted this workaround. I am not sure the ServiceNow node can know the value of a field on the target record before the update. Is it possible to check the target record’s state field value from within incoming sync rules on the ServiceNow side before making a decision whether to proceed with the sync?


Answer by Robbert Ijsselsteijn on 06 July 2023

Hey Rebecca,

I had the same issue when we were setting up our sync. This works very well for us:

if(replica.state \=\= "Canceled" \|\| replica.state \=\= "Closed"){workItem.comments \= commentHelper.addComment(

    "State was set to "\+replica.state\+" in serviceNow. Unexalating now.", workItem.comments)

syncHelper.unExalateAfterProcessing()

}

This also posts a message (if your target system is Azure DevOps at least) saying that the sync will stop in the comments from that point on.


Comments:

Rebecca Love commented on 06 July 2023

Hi Robbert Ijsselsteijn ,

This elegant solution works perfectly.

Thank you!

Rebecca

Answer by Sonal Otwani on 06 July 2023

Hi Rebecca Love

If you want to ignore changes to be done in ServiceNow incident if your service now status is closed, you can add following line:

if(replica.type.value == "Bug") { 
         if (!firstSync && entity.state?.name=="Closed"){
			return
		}
    	if (!firstSync && syncRequest.remoteSyncEventNumber == 1) {
			entity.u_devops_ref=replica.key
  		}
........


Let me know in. case of any concerns.

Thanks,

Sonal


Comments:

Rebecca Love commented on 06 July 2023

Hi Sonal Otwani ,

Here is the result.

Incoming script error
No such property: name for class: java.lang.String

Error line: 7

I’ve also tried:
if (!firstSync && entity.state.name==“Closed”){
if (!firstSync && entity.state==“Closed”){

Event though the recommendation below resolves the problem, I am curious about this possibility. Is there something else that might work here?

Thank you,

Rebecca

Sonal Otwani commented on 06 July 2023

Hi Rebecca Love ,

Can you let me know if following line does’t work:

if (!firstSync && entity.state==“Closed”){

Thanks,

Sonal

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.