How to set the "Multimedia link" field using the main service?

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

I try as below, I get an xml validation error. could you help with 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); 
+4
source share
2 answers

You must install xlink:href as here:

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

The easiest way to solve such problems is to create a component diagram with the appropriate field and the corresponding component. You will then find the answer by examining the XML component

+7
source

The approach for multimedia links is the same as for component links. And it also applies to both content and metadata fields. This example sets the link to the mm component in the metadata in the folder where the md diagram contains a sub-field named "versioned_component" containing the "component" field, which is the link field for multimedia components

 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

+3
source

Source: https://habr.com/ru/post/1438373/


All Articles