Jump to content

Omit record in Hub Willdelete section


Recommended Posts

Else If [ $whichAction = "WillDelete" ]

# ==================================================

#

#         A RECORD WILL BE DELETED ON THE HUB

#

# ==================================================

#     The found set will contain records that are about to be deleted by the sync

#     operation. You may omit any record from the found set. You may take actions

#     such as writing an audit log in in another table, or sending an e-mail. If

#     you omit the record from the found set, it will not be deleted, and will

#     be written back to the spoke on a future sync. If your script switches to

#     another layout, be sure to switch back to the original layout when it finishes.

Omit Record

End If

I have the above section in my Mirrorsync Script.

If I delete one record on the spoke it seems to work ok, the record will not get deleted on the Hub

If I delete all the records on the spoke, they get all deleted on the Hub.

Am I missing something ?

 

Link to comment
Share on other sites

Ok , after doing some tests I realize that the section is ran only once for the found set and not one for each record that will deleted.

So if I omit records [get(foundcount)]

It will work

1.So basically if I want to omit a particular record or to write an audit for each record that will be deleted I have to loop inside the found set

2.This is different than the didupdate and didinsert sections where they only have 1 record at a time

Am I correct on both points ?

Link to comment
Share on other sites

Posted (edited)

Hey sfpx,

Adam with 360Works here, happy to help.

1. If you want to conditionally omit particular records from your current found set, you can use the Constrain Found Set script step with an Omit Records action defined for it. If you want to write an audit for each record, you can certainly loop over each one to do that, just make sure that you end up back on the same layout that MirrorSync is expecting after all is said and done. Personally I would Constrain Found Set and then loop over them if necessary, as Constrain Found Set is a more efficient operation than performing an if comparison on each record and omitting it individually, especially if the fields your conditions are based on are indexed.

2. While the MirrorSync 6 script is within the DidInsert block it will usually have a larger found set, but the "current" record will be the newly inserted record. Note that you shouldn't change or sort the found set in this instance. While the script is within the "DidUpdate" section, you're correct that the found set will only contain one record.

Hope this was helpful! Have a great day.

Edited by Adam360Works
Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)
On 5/29/2024 at 1:39 PM, Adam360Works said:

Hey sfpx,

Adam with 360Works here, happy to help.

1. If you want to conditionally omit particular records from your current found set, you can use the Constrain Found Set script step with an Omit Records action defined for it. If you want to write an audit for each record, you can certainly loop over each one to do that, just make sure that you end up back on the same layout that MirrorSync is expecting after all is said and done. Personally I would Constrain Found Set and then loop over them if necessary, as Constrain Found Set is a more efficient operation than performing an if comparison on each record and omitting it individually, especially if the fields your conditions are based on are indexed.

2. While the MirrorSync 6 script is within the DidInsert block it will usually have a larger found set, but the "current" record will be the newly inserted record. Note that you shouldn't change or sort the found set in this instance. While the script is within the "DidUpdate" section, you're correct that the found set will only contain one record.

Hope this was helpful! Have a great day.

Thanks Adam.

After some thoughts we decided to use a different approach to deletion.

Our idea is

1.Have a MarkedToDelete field in all the tables

2.Prior to the deletion on the spoke, an api call would be made to set the field MarkedToDelete to 1 for the record. Then it would be deleted on the spoke.

3.In mirrorsync, in the "A RECORD WILL BE DELETED ON THE HUB" section, all the records that would not have MarkedToDelete set to 1 would be omitted.

 

I think it should work.

Now I'm wondering if the api call should also delete the record instead of using mirrorsync.

How would mirrorync handle it if a record is deleted on the spoke and on the hub at the same time (but existed in the previous sync)

 

 

 

Edited by sfpx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.