How do i transfer data from one CHw to another

hi team,

I was kindly requesting for some guidance and assistance on how to transfer data for example transfer households under a CHw to another CHw.

We are facing a scenario where two CHWs are leaving and for both of them, we would love to transfer that data to one already existing CHw.

What could be the best way to do this ?

The cht-conf move-contacts command is the recommended way to do this. Because of the CHT’s offline-first nature, moving contacts between users is not super convenient since it involves re-aligning the data that a user has access to, but the linked docs get into more specifics about the tradeoffs involved. (Also worth noting that the cht-user-management tool includes some functionality for helping to generate these move-contact commands.)

Also worth calling out that for your case of merging contacts from one user into another existing user, the move-contacts command makes the most sense. For different cases where perhaps you are replacing one user with another new user the create_new_user Sentinel transition provides some different functionality for doing this (even works offline).

1 Like

Hi @jkuester

Thank you for your timely response.

After transferring the contact 1 to the parent, The household was able to move to the parent though the members were missing even after syncing .

Indicates that all documents have been uploaded to the parent successfully.

The parent where they have been transferred having the household but missing members (ABA FGG Household)

The parent from which they have been transferred from still having the household (ABA FGG Household) and the members even after syncing.

Indication that the documents transferred included the members

What could i have missed?

First I just want to confirm that this is expected behavior as noted in the docs:

Offline users who have contacts removed from their visible hierarchy will not automatically see those contacts disappear.

Because of how the syncing algorithm works to determine which docs are visible to a user, currently when docs are moved so that a user no longer has access to them, in order for that user to not see those does anymore, you have to clear their cache and do a re-sync.

When testing on a browser, I use the “Clear site data” button on the Application tab of Chome’s DevTools:

After clearing the site data and logging back in as the user, the moved contacts should no longer be visible.


This, however, is unexpected. Here are some things we can check first:

  1. Can you provide the exact move-contacts/upload-docs commands you ran? (with some notes about which contacts are associated with the relevant ids)
  2. In the local json files for the moved contacts (by default these are in ./json_docs) can you confirm that the grandparent id has been updated in the file to point to the new CHW Area? The move-contacts command should have set the parent.parent._id value to match the id of the target CHW area (presumably this was the value you provided for --parent).
  3. If the local json files were updated correctly, can you then confirm that the data in Couch was updated as expected. (e.g. use Fauxton to validate that the docs in Couch for these missing contacts match what is in the local json files)
  4. The target user should not have to logout or clear any data. All they should need to do to see the moved contacts should be to sync successfully. Can you re-try the sync again and confirm the “All reports synced” message is shown? Also can you check the browser console logs when you do this for any suspicious errors?
  5. Finally, if all else fails, can you try clearing the data for the target user and re-syncing everything? As I said before, I don’t know of any reason why this should make a difference, but for debugging it would be useful to know the result of a fresh sync…

@jkuester Thankyou for the support

In the admin account, it shows that the members are present. yet in the chw account it doesn’t . This shows that the parent.parent._id value match?

cht --instance= move-contacts – --contacts=3b05b05d-a8c9-4cab-b669-8c5e3b07e306 --parent=e9262cc226960e929dabca03710a344e --docDirectoryPath=my_folder

This created a folder called ( my_folder )with different ids
cht --url=https://**@cht.guilddigital.co/l upload-docs – --docDirectoryPath=my_folder

I have re-synced still persisting

That clearing the cache, the chw account still lacks members yet they are visible in the admin account above

Ah, yes! If things look as expected in the admin account, this should confirm that the update was successful on the server side. This means we can focus our efforts on understanding why the child contacts are not syncing to the new user.

The first thing to check is if you have replication_depth configured for the role(s) of the new user. Does the new user have the same or different roles as the original one? Can the new user see household members in other (existing) households?

The other main thing that would affect which docs get replicated to a user is the purging configuration. Do you have any purging configured for the new user’s role(s)? If so, it would be good to review that configuration and determine if it might be affecting these household members.

The fact that the household shows up for the new user, but not the members makes me think it is very likely to be one of these configuration options. Otherwise, there should not be anything that prevents the household members from being replicated…

2 Likes

Hi @jkuester

Thank you so much. It has worked.

So i updated the replication depth from 1 to 3 And the members showed up .

3 Likes