In a migration project after the database synchronization you might come up with a scenario to link the BPT in all the publications. Though there is an option to manually set that BPT in all publications from the UI interface but it is easier to update that through the Content Management API (Core service), once you have lots of web site publication.
Let’s take an example:-
Imagine you have more than 30 web sites publication [master sites (starts with 600) and localized sites (starts with 700)]. Now in all the publication you want to update the newly created BPT which is monotonous and lengthy job to perform through UI interface. To achieve that you can run the below script –
Functionality of the script:
- Find all the publications where title starts with 600 or 700.
- Check the Business Process Type for those publication.
- Read the new BPT id. (Here I have added the id in the app.config, but you can read it using the coreservice as well )
- If the linked BPT for that publication is Null then add the BPT id in that publication and Save the changes.
static void Main(string[] args)
{
using (var client = Utility.CoreServiceClient)
{
// get the list of the publications.
var publications = client.GetSystemWideList(new RepositoriesFilterData());
foreach (var pub in publications.Where(p => p.Title.Contains("600) || p.Title.Contains("700"))
{
// Read Publication details.
var publication = (RepositoryData)client.Read(pub.Id, new ReadOptions());
// Check the BPT of that publication, if null then add the BPT to that.
if (publication.BusinessProcessType == null || publication.BusinessProcessType.IdRef == "tcm:0-0-0")
{
// Reading the BPT id from the app.config, But you can also to read it through the core service.
int sourceBptId = Convert.ToInt32(ConfigurationManager.AppSettings["SourceBptId"]);
TcmUri bptId = new TcmUri(sourceBptId, Tridion.ContentManager.ItemType.BusinessProcessType, new TcmUri(publication.Id).ItemId);
//Link the BPT id to that publication.
publication.BusinessProcessType = new LinkToBusinessProcessTypeData { IdRef = bptId };
//Save.
client.Save(publication, new ReadOptions());
}
}
}
}
That’s it. You can find the source code here.