Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create Bundle Using Tridion Coreservice [C# version]
function New-TridionBundle
{
<#
.Synopsis
Creates a new bundle based on specified bundle schema.
.Inputs
None.
.Outputs
Returns the newly created bundle.
#>
[CmdletBinding()]
Param
(
# The title of the new bundle
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Title,
# The descrition of the new bundle
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Description,
# The item type of the new bundle
[Parameter(Mandatory=$true)]
[string]$BundleSchemaId,
# ID of the parent folder.
[Parameter(Mandatory=$true)]
[string]$Parent
)
Begin
{
$client = Get-TridionCoreServiceClient -Verbose:($PSBoundParameters['Verbose'] -eq $true);
}
Process
{
$virtualFolderTypeSchema = $client.GetVirtualFolderTypeSchema("http://www.sdltridion.com/ContentManager/Bundle");
$bundle = _GetDefaultData $client 8192 $Parent $Title;
$bundle.Description = $Description;
$bundle.MetadataSchema.IdRef= $BundleSchemaId;
$bundle.TypeSchema.IdRef = $virtualFolderTypeSchema.Id;
$bundle.LocationInfo.OrganizationalItem.IdRef = $Parent;
$bundle.Configuration = '<Bundle xmlns="http://www.sdltridion.com/ContentManager/Bundle"><Items/></Bundle>';
$result = _SaveItem $client $bundle $true;
return $result;
}
End
{
Close-TridionCoreServiceClient $client;
}
}
public VirtualFolderData CreateBundle()
{
SchemaData bundleSchema = (SchemaData) _CoreServiceClient.Read("tcm:1-78-8", _ReadOption);
SchemaData virtualFolderTypeSchema =
_CoreServiceClient.GetVirtualFolderTypeSchema(@"http://www.sdltridion.com/ContentManager/Bundle");
TcmUri folderId = new TcmUri(100, ItemType.Folder, 1);
VirtualFolderData bundle = new VirtualFolderData()
{
Id = "tcm:0-0-0",
Title = "Test Bundle Title",
Description = "Test Bundle Description",
MetadataSchema = new LinkToSchemaData()
{
IdRef = bundleSchema.Id
},
TypeSchema = new LinkToSchemaData()
{
IdRef = virtualFolderTypeSchema.Id
},
LocationInfo = new LocationInfo()
{
OrganizationalItem = new LinkToOrganizationalItemData()
{
IdRef = folderId
}
}
};
bundle = (VirtualFolderData) _CoreServiceClient.Create(bundle, _ReadOption);
return bundle;
}
@justsayantan

This comment has been minimized.

Copy link
Owner Author

@justsayantan justsayantan commented Jun 5, 2018

Here is the scripts to create bundle/bundles through PowerShell coreservice module. Though I have mentioned about the PowerShell module, but I considered to keep C# version as well, so that anyone can pick as per their preference –

To create the Bundle I have used below Parameters –

Parameter Description
Title Title of the Bundle
Description Description Of the Bundle
BundleSchemaId Id of the Bundle Schema (Based on which the Bundle will be created)
Parent Id of the Folder (Where you want to place the Bundle)

Here is an example to create a no. of Bundles at the same time –

// Here I am creating a new folder to store all the bundles at the same place

$newFolder = New-TridionItem -ItemType 2 -Parent tcm:5-27-2 -Name Bundles
Write-Host “Folder Id: ” $newFolder.Id
Write-Host “=====================”

$count = 10;
for($i=0; $i -le $count;$i++)
{
$title = “My New Bundle ” + $i;
$Description = “Bundle along with updated component”
$bundleid = New-TridionBundle -Title $title -Description $Description -BundleSchemaId “tcm:5-403-8” -Parent $newFolder.Id
Write-Host “New Bundle Id” $bundleid
Write-Host “=====================”
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment