I have grouped contacts as follows: I want to use scripting to move Contact1 to Group2 folder, how do I do that ?
There is no scripting API that imitates "drag and drop" functionality to move the object from one tree grouping folder to another. However, we can obtain the same result by modifying the tree grouping folders.
See example code below:
# user inputs contact_name = "Contact1" origin_folder_name = "Group1" destination_folder_name = "Group2" # move contact from one folder to the other ## get origin folder, destination folder, and contact origin_folder = [folder for folder in DataModel.GetObjectsByType(DataModelObjectCategory.TreeGroupingFolder) if folder.Name==origin_folder_name][0] moved_contact = [contact for contact in origin_folder.Children if contact.Name==contact_name][0] destination_folder = [folder for folder in DataModel.GetObjectsByType(DataModelObjectCategory.TreeGroupingFolder) if folder.Name==destination_folder_name][0] # create lists for items to stay in old folder and items for new folder modified_origin_list = [child for child in origin_folder.Children if child != moved_contact] modified_destination_list = destination_folder.Children modified_destination_list.Add(moved_contact) # ungroup folders Tree.Ungroup(origin_folder) Tree.Ungroup(destination_folder) # re-create tree grouping folders new_origin_folder = Tree.Group(modified_origin_list) new_origin_folder.Name = origin_folder_name new_destination_folder = Tree.Group(modified_destination_list) new_destination_folder.Name = destination_folder_name
We can check that the contact has been moved: