How does Sitecore Update Package Work – Creating Property Commands

Posted 10/20/2016 by Subramanian Ramanathan

As we discussed in the previous blogs, we have created Item/Version/Field Commands and in continuation to it, we can create Property Commands in this blog.

When we look at an item in Sitecore we would have certain properties under ‘Quick Info’ section. For changing these properties we will have use ChangePropertyCommand.

Quick Info

For Creating Change Property Commands we will have to create ChangeEntry as below,

//Changing Item Name
ChangeEntry itemNameChangeEntry = new ChangeEntry("name", "Old Item Name", "New Item Name");

//Changing Template ID
ChangeEntry templateIdChangeEntry = new ChangeEntry("templateid", "{...}", "{...}");

//Changing Parent ID (Item Path)
//This moves the item to the new path in Sitecore
ChangeEntry parentIdChangeEntry = new ChangeEntry("parentid", "{...}", "{...}");

//Changing Branch ID (Created from)
//This changes the Branch Template if the Item is created based on a Branch Template
ChangeEntry branchIdChangeEntry = new ChangeEntry("branchid", "{...}", "{...}");

//Creating the List of Changes
List changeEntries = new List();

//Creating Change Property Command
ChangePropertyCommand changePropertyCommand = new ChangePropertyCommand(dataItem, changeEntries);

Similar to Item Commands, Collision Behavior for Field Commands can be Force(default) or Skip.
If Collision Behavior is not set or is set to Force, then the existing items will be overwritten if there is a collision and the Action would be 'Overwrite Existing'. If Collision Behaviour is set to Skip, then the existing items will not be updated if there is a collision and the Action would be 'Keep Existing'.

//Updates with New Value only if Old Value is not different
changePropertyCommand.CollisionBehavior = CollisionBehavior.Skip;

After creating the Property Commands, it has to be added to the ChangeItemCommand before creating the update package.

List innerCommands = new List();
ChangeItemCommand changeItemCommand = new ChangeItemCommand(dataItem, innerCommands);


Add your comment