After lot of investigation, I have seen that the Branch Template cannot be used since I get the following error:
Template is invalid (cdbb9572-14b6-4ea2-818e-bb6c15beda94)
The reason is because of the Add Method from the namespace
Sitecore.Services.Infrastructure.Sitecore.Data.ItemRepository
Below is the Code for creating the item:
public Guid Add(ItemCreateRequest request, string databaseName, string language)
{
Database database = ItemRepository.GetDatabase(databaseName);
Language language1 = ItemDataBase.GetLanguage(language);
Item obj = database.GetItem(request.ParentPath, language1);
if (obj == null)
throw new ArgumentException(ItemDataBase.InvalidParameterMessage("Path", (object) request.ParentPath));
TemplateItem template = database.GetTemplate(new ID(request.Template));
if (template == null)
throw new ArgumentException(ItemDataBase.InvalidParameterMessage("Template", (object) request.Template));
Item itemToUpdate = obj.Add(request.Name, template);
using (new EditContext(itemToUpdate))
this.UpdateFields(request.Fields, itemToUpdate);
return itemToUpdate.ID.Guid;
}
The above code is used for creating an item from a template and not from a Branch Template. For Branch Template it should have been as below:
private const string _BRANCH_ITEM = "/sitecore/templates/Branches/MyBranches/MyBranch";
public void Create(Item parent, string name)
{
BranchItem branch = globalDataFolder.Database.GetItem(_BRANCH_ITEM);
Assert.IsNotNull(branch, "Could not find Data branch at " + _BRANCH_ITEM);
parent.Add(name, branch);
}
The difference is instead of using TemplateItem
, it need to be changed to BranchItem
in order to create item from Branch Template. Example is taken from Brian Pedersen post
It seems that the only way to achieve this is to override the ItemRepository and implement a new method that caters for Branch Template. Maybe, introducing the creation of items from Branch Template in future releases of the Sitecore Data Exchange Framework might be considered.