0

I want to add Page metadata Schema to a Page which does not contain any metadata Schema attached to it. How can we achieve this?

I'm currently using an external script. I have tried searching the syntax for doing this. However, none of them have specified the Interop syntax for doing it.

ItemFields metadata = p.MetadataFields;
metadata["MetadataSchema"].value.Add("Page Metadata");

The above code throws the following error:

Object reference not set to an instance of an object.

I have also tried using syntax, that allows to add/update values of the text field in the Page, however that syntax does not seem to work for updating the metadata Schema.

2
  • Can you edit your question and supply a few more details around where you want to automate this exactly (is it in a Template Building Block, in an event handler or in an external script etc.), and what investigation you have done yourself already? Jun 4, 2018 at 11:46
  • Can you please update your question with more detail please.
    – Marko Milic
    Jun 5, 2018 at 7:37

1 Answer 1

3

I have found the solution:

Page p = (Page)tdse.GetObject("tcm:12-1468760-64", EnumOpenMode.OpenModeView);
Schema schema = (Schema)tdse.GetObject("tcm:12-761677-8", EnumOpenMode.OpenModeView);
p.MetadataSchema = schema;
p.Save();
p.CheckIn();

Your Answer

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

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