Differential Sync
The differentialSync function will optimally update a large set of data based on a comparison of existing data. The function takes many arguments, most notably the newOverride, updateOverride and deleteOverride; those 3 parameters can allow you to write custom code that will handle new, updates or deletions.
Parameters
- elementName - String (Required)
- The element name that we are going to sync.
- newElements - Array (Required)
- The elements that you would like to have as the result after the sync is complete
- preformDelete - Boolean
- default: false
- This will call the delete function if set to true, otherwise deletions will not be processed. This can be helpful if you want old elements to remain.
- primaryKeys - String
- List of primary keys to use in the comparision
- _pageID is a reserved word and will compare the elements pageID if it exists in the source data
- Example: "links,title" or "_pageID,title"
- ignoreFields - String
- A list of fields to ignore in the comparison.
- Example: "id,title"
- newOverride - Structure
- default:
- newOverride.bean = "csContent_1_0"
- newOverride.method = "populateContent_1_0"
- You can override this to handle all new items with your own bean/method argument. It will get called with the parameter of "data" which is a structure of the element data. It will also get a paremter of elementName which is the ccapiName of the element.
- default:
- updateOverride - Structure
- default:
- updateOverride.bean = "csContent_1_0"
- updateOverride.method = "populateContent_1_0"
- You can override this to handle all items that changed with your own bean/method argument. It will get called with the parameter of "data" which is a structure ot the element data. It will also get a paremter of elementName which is the ccapiName of the element.
- default:
- deleteOverride - Structure
- default:
- deleteOverride.bean = "ceData_1_0"
- deleteOverride.method = "deleteCE"
- You can override this to handle all items that should be deleted with your own bean/method argument. It will get called with the parameter of datapageidList as a list of data page id's to be deleted. One reason why you may use this is do "deactivate" an item instead of deleting it
- default:
- syncSourceContent - Array
- Accepts an array of CE data
- If you pass syncSourceContent it will use that data instead of pulling the data based on element name. This can be useful when you only want to sync a small set of data against another smaller set. It can also be helpful when your data may live in multiple locations and you need to combine them together prior to sync.
- elementCCAPIName
- Default: arguments.elementName
- This is the CCAPI name for the element, this is used when calling the new and update methods
Sample Call
myNewElements = ArrayNew(1); myNewElements[1].values = StructNew(); myNewElements[1].values.id = "1234"; myNewElements[1].values.title = "title"; myNewElements[1].values.description = "This should be ignored"; myDeleteOverride = StructNew(); myDeleteOverride.bean = "myCustomBean"; myDeleteOverride.method = "myCustomMethod"; application.ADF.ceData.differentialSync( elementName="MyElementName", newElements=myNewElements, preformDelete=true, primaryKeys="id", ignoreFields="description", deleteOverride=myDeleteOverride, elementCCAPIName="myElementCCAPINAme" );
Lets walk through that, firstly we create an array of ce_data
myNewElements = ArrayNew(1); myNewElements[1].values = StructNew(); myNewElements[1].values.id = "1234"; myNewElements[1].values.title = "title"; myNewElements[1].values.description = "This should be ignored";
This data could be pulled from a database and built dynamically, it could be data extracted from virtually any datasource, including CommonSpot itself. It simply needs to be formatted as an array of CE data.
Then we define a deletion override:
myDeleteOverride = StructNew(); myDeleteOverride.bean = "myCustomBean"; myDeleteOverride.method = "myCustomMethod";
It will utilize the application.ADF.utils.runCommand function to execute this override.
Then we call the meat of the differential sync with our parameters:
application.ADF.ceData.differentialSync( elementName="MyElementName", newElements=myNewElements, preformDelete=true, primaryKeys="id", ignoreFields="description", deleteOverride=myDeleteOverride, elementCCAPIName="myElementCCAPINAme" );
This sync will sync on the element "MyElementName", it will process the deletions using our override method. It will align items for comparision using the ID field and it will not compare the description field. It will process new and updated items using the "myElementCCAPINAme" as the ccapi element name.