Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Multimedia Link field using Core service?

I would like to set the Multimedia link fied for the component metadata using core service.

I am trying like below, am getting xml validation error. could you pleaes help on this?

        ComponentData comp = client.Read(compid, readoption) as ComponentData;
        comp = client.TryCheckOut(compid, readoption) as ComponentData;

        string newxml = @"<Metadata xmlns=""uuid:5880d67f-13f7-4632-8c33-dcfd9c1437ed"">
                          <meta>
                          <mmlink>tcm:22-5678</mmlink>        

                          </metad>
                          </Metadata>";

        comp.Metadata = newxml;

        client.Save(comp, readoption);
        client.CheckIn(comp.Id, readoption);
like image 598
user1428019 Avatar asked Dec 26 '22 16:12

user1428019


2 Answers

You should set xlink:href like here:

<mmlink xlink:type="simple" xlink:href="tcm:2-146" 
        xmlns:xlink="http://www.w3.org/1999/xlink"></mmlink>

The easiest way to solve problems like this is to create a component schema with the field in question and corresponding component. You will then find the answer by exploring component XML

like image 133
Andrey Marchuk Avatar answered Jan 29 '23 02:01

Andrey Marchuk


The approach for Multimedia Links is the same than for Component Links. And it also applies for both, content and metadata fields: This example is setting a mm component link in a folder metadata where the md schema constains a embeddable field called "versioned_component" containing a field called "component" which is a multimedia component link field:

this.OpenSession();
try
{
    //itemUri is the MM Component uri
    var currentItem = (ComponentData)session.Read(itemUri, new ReadOptions());
    LinkToRepositoryData ltrd = currentItem.LocationInfo.ContextRepository;
    var pd = (PublicationData)session.Read(ltrd.IdRef, new ReadOptions());
    String currentPublicationWebdavURL = pd.LocationInfo.WebDavUrl;
    String schemaUri = string.Format(FOLDER_MD_SCHEMA_WEBDAVURL, 
                          HttpUtility.UrlDecode(currentPublicationWebdavURL));

    //schemaUri = HttpUtility.UrlEncode(schemaUri);
    var sd = (SchemaData)session.Read(schemaUri, new ReadOptions());
    FolderData folder = new FolderData();
    folder.Id = TcmUri.UriNull;
    folder.Title = "hidden_" + Guid.NewGuid().ToString();
    var rootFolder = (FolderData)session.Read(
                            currentItem.LocationInfo.OrganizationalItem.IdRef, 
                            new ReadOptions());
    folder.LocationInfo= new LocationInfo()
    {
        OrganizationalItem = new LinkToOrganizationalItemData(){
            IdRef = rootFolder.Id
        }
    };
    folder.MetadataSchema = new LinkToSchemaData()
    {
        IdRef = sd.Id,
    };
    string sMetadata = "<Metadata xmlns=\"{0}\" xmlns:xlink=\"{1}\"> " 
                     + "  <version_component>" 
                     + "    <component xlink:type=\"simple\" " 
                     + "          xlink:href=\"{2}\" xlink:title=\"{3}\" />" 
                     + "  </version_component> " 
                     + "</Metadata>";
    sMetadata = string.Format(sMetadata, sd.NamespaceUri, 
                              Tridion.Constants.XlinkNamespace, 
                              currentItem.Id.ToString(), currentItem.Title);
    folder.Metadata = sMetadata;
    folderUri = session.Save(folder, new ReadOptions()).Id.ToString();
    return folderUri;
}
finally {
    this.CloseSession();
}

Hope this helps too,

like image 32
Jaime Santos Alcón Avatar answered Jan 29 '23 02:01

Jaime Santos Alcón