3

SUMMARY

Whilst creating and populating a Bundle using PowerShell - I'd also like to assign a specific Bundle Schema to the Bundle so that I am able to then start the workflow process associated with it...

$bundleWFlowSchemaId = "tcm:99-36586-8";
$bundle.MetadataSchema = new-object LinkToSchemaData;
$bundle.MetadataSchema.IdRef = $bundleWFlowSchema.Id

this seems to be trying to attach the correct schema given it refers to it (xxxschema) in the error but I'm not certain I'm adding this to the right object?

> Exception calling "Create" with "2" argument(s): "Unable to find
> http://contentbloom.net/tridion/schemas/workflow/xxxschema:Metadata."
> At line:21 char:5
> +     $core.Create($bundle, $defaultReadOptions);
> +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
>     + FullyQualifiedErrorId : FaultException`1

BACKGROUND

Extending from my question on Error in Virtual Folder Type creating Bundle in PowerShell I'd like to know know how to add a specific Workflow Bundle Schema the Bundle (the next step will be to start' the respective process to finish).

Attempt 1

Taking the following that will successfully create (and populate if <items> are added into $bundle.Configuration) a Bundle.

$bundleFolderData = new-object VirtualFolderData
$location="tcm:aa-bb-2";
$bundle = $core.GetDefaultData([ItemType]::VirtualFolder, $location, $defaultReadOptions);
$bundle.Configuration = "<Bundle xmlns=""http://www.sdltridion.com/ContentManager/Bundle""><Items /></Bundle>"
$bundleSchemaId = $schema.Id
$bundle.TypeSchema.IdRef = $bundleSchemaId
$core.Create($bundle, $defaultReadOptions)

And seeing the c# as something along the lines of:

        var bundleSchema = (SchemaData)svc.Session.Read(schemaUriOrWebdav, new ReadOptions());
        var bundleSchemaUri = new Tcm.TcmUri(bundleSchema.Id);
        var publicationUri = new Tcm.TcmUri(contextPublicationUri);
        if (bundleSchemaUri.PublicationId != publicationUri.ItemId) {
            var contextSchemaUri = GetBluePrintItemTcmId(bundleSchemaUri, contextPublicationUri);
            bundleSchema = (SchemaData)svc.Session.Read(contextSchemaUri, new ReadOptions()); ;
        }

I can use

            MetadataSchema = new LinkToSchemaData()
            {
                IdRef = bundleSchema.Id
            }

And then add this to the bundle metadata. [1]

So ... let's PowerShell this up, I hoped:

$bundleWFlowSchemaId = "tcm:x-x-8";
$bundleWFlowSchema = $core.Read ($bundleWFlowSchemaId, $defaultReadOptions)
$bundle.Metadata = $bundleWFlowSchema

But, this gives the error:

Exception calling "Create" with "2" argument(s): "The formatter threw an exception while trying to deserialize the message: There was an error while trying to 
deserialize parameter http://www.sdltridion.com/ContentManager/CoreService/2013:data. The InnerException message was 'There was an error deserializing the object 
of type Tridion.ContentManager.Data.IdentifiableObjectData. Data at the root level is invalid. Line 1, position 1.'.  Please see InnerException for more details."
At line:21 char:5
+     $core.Create($bundle, $defaultReadOptions);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FaultException

Attempt 2

Well really this wasn't just my second attempt but I've missed out the annoying and the embarrassing

I thought it was odd getting a serialization error - something I've seen a lot of before when dealing with metadata.

Then it occurred that it's not metadata I'm updating here - it's the Bundle Workflow Schema so I reviewed the code and realised that the MetadataSchema and Metadata are NOT the same thing (kinda obvious on reflection!)

$bundleWFlowSchemaId = "tcm:$locationId-36586-8";
#$bundleWFlowSchema = $core.Read($bundleWFlowSchemaId, $defaultReadOptions)
$bundle.MetadataSchema = new-object LinkToSchemaData;
$bundle.MetadataSchema.IdRef = $bundleWFlowSchema.Id

now this seems to be trying to attach the schema given it refers to it (xxxschema) in the error:

Exception calling "Create" with "2" argument(s): "Unable to find http://contentbloom.net/tridion/schemas/workflow/xxxschema:Metadata."
At line:21 char:5
+     $core.Create($bundle, $defaultReadOptions);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FaultException`1

I thought it was odd getting a serialization error - something I've seen a lot of before when dealing with metadata.

Then it occurred that it's not metadata I'm updating here - it's the Bundle Workflow Schema so I reviewed the code and realised that the MetadataSchema and Metadata are NOT the same thing (kinda obvious on reflection!)

$bundleWFlowSchemaId = "tcm:$locationId-36586-8";
#$bundleWFlowSchema = $core.Read($bundleWFlowSchemaId, $defaultReadOptions)
$bundle.MetadataSchema = new-object LinkToSchemaData;
$bundle.MetadataSchema.IdRef = $bundleWFlowSchema.Id

now this seems to be trying to attach the schema given it refers to it (xxxschema) in the error:

Exception calling "Create" with "2" argument(s): "Unable to find http://contentbloom.net/tridion/schemas/workflow/xxxschema:Metadata."
At line:21 char:5
+     $core.Create($bundle, $defaultReadOptions);
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FaultException`1

3 Answers 3

4
function createBundle($config, $metadataXmlContent, $title, $locationPubId, $locationFolderId, $metadataSchemaId){

    $bundle = $null;

    $bundleNameSpace = "http://www.sdltridion.com/ContentManager/Bundle";
    [SchemaData]$schema = $core.GetVirtualFolderTypeSchema($bundleNameSpace);
    $bundleSchemaId = $schema.Id;

    if ([string]::IsNullOrEmpty($locationFolderId)) {
     $locationFolderId = "555";
    }

    if ([string]::IsNullOrEmpty($title)) {
        $title = "xTECH MSA from Query $locationId"
    }

    if ([string]::IsNullOrEmpty($metadataSChemaId)) {
        $metadataSchemaId = "55555"
    }

    $location="tcm:$locationPubId-$locationFolderId-2"; 

    $metadataNS = "xmlns=""http://corp.alldata.net/tridion/schemas/workflow/ac-content-escalation""" #todo: get this from the schema directly
    $bundleNameSpace
    $bundle = $core.GetDefaultData([ItemType]::VirtualFolder, $location, $defaultReadOptions);
    $bundle.TypeSchema = new-object LinkToSchemaData;
    $bundle.TypeSchema.IdRef = $bundleSchemaId;
    $bundle.Title = $title;
    $bundle.Configuration = "<Bundle xmlns=""http://www.sdltridion.com/ContentManager/Bundle""><Items /></Bundle>";
    $bundle.Configuration = $config;

    [LinktoSchemaData]$metadataSchema = new-object LinktoSchemaData
    $metadataSchema.IdRef = "tcm:$locationId-$metadataSchemaId-8"

    $bundle.MetadataSchema = $metadataSchema;
    $metadata="<Metadata $metadataNS>$metadataXmlContent</Metadata>"
    $bundle.Metadata = $metadata

    Write-Output "Creating bundle '$title' in $location";

    $core.Create($bundle, $defaultReadOptions);
}


$core = Get-TridionCoreServiceClient
$pub = "55";
$config  ="<Bundle xmlns=""http://www.sdltridion.com/ContentManager/Bundle""><Items xmlns=""http://www.sdltridion.com/ContentManager/Bundle""><Item xmlns:xlink=""http://www.w3.org/1999/xlink"" xlink:href=""tcm:92-27665-16"" xlink:title=""Dummy title here - will be replaced by CMS on save""></Item></Items></Bundle>";
$metadataXmlContent = "<releaseId>TEST " + $pub + "</releaseId>"; 
createBundle $config $metadataXmlContent $null $pub $null $null;
3

I'll just answer the latest edit to your question:

Exception calling "Create" with "2" argument(s): "Unable to find http://contentbloom.net/tridion/schemas/workflow/xxxschema:Metadata." At line:21 char:5

This error suggests that you haven't specified the actual Metadata XML. You do that through the Metadata property that you mistakenly used previously. At the very least, you will need the Metadata element (in the namespace of the Metadata Schema). You'll likely need to add more elements under it, but that part depends on the exact Schema.

1
  • DOH! I'll give this a try shortly, thanks Peter! +1 for now... Commented Feb 8, 2016 at 10:36
2

here's what I do. I think some of my helper methods should be clear enough to figure out. if not, let me know.

$folder = Get-TridionItem -IdOrPath (Get-EncodedWebdavUrl -WebdavUrl $WebdavLocation)
if ($folder -eq $null)
{
    Add-ScriptWarningMessage -Message "Unable to find folder for Bundle: $WebdavLocation"
    return $null
}
$itemTypeVirtualFolder = 8192  
$schema = Get-TridionItem -IdOrPath (Get-EncodedWebdavUrl "/webdav//Bundle.xsd")
if ($schema -ne $null)
{
    $schemaLink = New-Object Tridion.ContentManager.CoreService.Client.LinkToSchemaData
    $schemaId = $schema.Id
    $schemaLink.IdRef = $schemaId
}
else
{
    Add-ScriptWarningMessage -Message "Unable to locate Schema"
    return $null
}

$bundle = [Tridion.ContentManager.CoreService.Client.VirtualFolderData]$client.GetDefaultData($itemTypeVirtualFolder, $folder.Id, (New-Object Tridion.ContentManager.CoreService.Client.ReadOptions));
$bundle.Title = $Name
$bundle.TypeSchema = $schemaLink
#this is a "magic" piece that is required to create a bundle!!!
$bundle.Configuration = "<Bundle xmlns=`"http://www.sdltridion.com/ContentManager/Bundle`"><Items /></Bundle>"
if (-Not ([string]::IsNullOrEmpty($BundleType)))
{
    #code for this helper method is shown above for getting Bundle Schema
  $bundle.MetadataSchema = (Get-TridionLinkToSchemaData -SchemaWebDavUrl (Get-EncodedWebdavUrl -WebdavUrl $BundleType))
  if (-Not ([string]::IsNullOrWhiteSpace($MetadataXml)))
  {
    Write-Verbose -Message "Adding metadata: $MetadataXml"
    $bundle.Metadata = $MetadataXml
  }
}
$bundle = $client.Create($bundle,(New-Object Tridion.ContentManager.CoreService.Client.ReadOptions))
1
  • Thanks for the response Warner. I can't see where your code is different than this above in creating a bundle ..... $bundle.MetadataSchema = new-object LinkToSchemaData; $bundleWFlowSchemaId = "tcm:x-x-8"; $bundle.MetadataSchema.IdRef = $bundleWFlowSchema.Id Can you be specific as to where you're adding the metadata schema and what's different? Commented Feb 8, 2016 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.