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.

  • 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? – Bart Koopman Jun 4 '18 at 11:46
  • Can you please update your question with more detail please. – Marko Milic Jun 5 '18 at 7:37
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();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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