3

I have used the below code to set Default Multimedia Schema while creating a multimedia Component.

ComponentData multimediaComponent = (ComponentData) client.getDefaultData(ItemType.COMPONENT, "tcm:246-95-2");
LinkToSchemaData linkToSchemaData = new LinkToSchemaData();
linkToSchemaData.setIdRef(objectFactory.createLinkIdRef("tcm:246-243-8"));
multimediaComponent.setSchema(objectFactory.createLinkToSchemaData(linkToSchemaData));

When I try to run the code I have noticed that the Schema is not correctly set. Can anyone suggest me if there is any other way I can set the Schema reference to create a multimedia Component in SDL Tridion or is there anything I need to change in the above code?

2
  • 1
    This appears to be related to tridion.stackexchange.com/q/1125/129 although I'm not sure if it should be a duplicate. Are you asking the same question two different ways? :-) Commented May 4, 2013 at 11:52
  • @DominicCronin : Yes, Domnic. Actually I am facing an issue with setting the schema to multimedia component. So I have posted only the Code where in I am creating a link to multimedia schema. :-) Commented May 6, 2013 at 3:25

1 Answer 1

2

You mention that the Schema is not correctly set, what exactly does that mean? It would help a lot if you could specify where you get an error (compile time or runtime and with what details/stack trace?).

I'm not so familiar with the Core Service Java API, but I was under the impression you could simply set the Schema as follows (no need to use the objectFactory twice in there):

LinkToSchemaData linkToSchemaData = new LinkToSchemaData();
linkToSchemaData.IdRef = "tcm:246-243-8";
multimediaComponent.setSchema(linkToSchemaData);

When reading the example in the documentation (which is using the objectFactory), it would translate to something like this I think:

LinkToSchemaData linkToSchemaData = objectFactory.createLinkToSchemaData();
linkToSchemaData.setIdRef(objectFactory.createLinkIdRef("tcm:246-243-8"));
multimediaComponent.setSchema(objectFactory.createComponentDataSchema(linkToSchemaData));
3
  • When I try to save the multimedia component it is raising an exception - "Unable to get Schema of component". Commented May 3, 2013 at 8:28
  • In Java we dont have the method ".IdRef". We have ".setIdRef()" which accepts a JAXBElement<String> as a parameter. So I created Object factory to setIdRef. Commented May 3, 2013 at 8:36
  • I guess it all depends on how you create your proxy, see also Mihai's articles on using the Core Service in Java yatb.mitza.net/search/label/Core%20Service Commented May 3, 2013 at 8:54

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.