1
0
-1

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?  

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      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.

      1. Rebecca Love

        Hi Robbert Ijsselsteijn ,


        This elegant solution works perfectly.


        Thank you!


        Rebecca

      CommentAdd your comment...
    2.  
      2
      1
      0

      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

      1. Rebecca Love

        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

      2. Sonal Otwani

        Hi Rebecca Love ,


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

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


        Thanks,

        Sonal

      CommentAdd your comment...