How to save some metadata on a document?

I’ve been trying for a few days now different ways to save some data on a document level, so that when document is opened again, plugin would perform some actions if that data is set. No luck at all :frowning:

I didn’t want to deal with XML, so I decided to first try json property (saw @Jarda mentioning it here), but couldn’t make it work - either I got no error at all and property was not saved (but most likely descriptor was wrong), or I got error:

“Set” is not currently available

My final descriptor (also tried without _ref: "property"):

    _obj: "set",
    _target: [
        {_ref: "property", _property: property},
        {_ref: "document", _id: docId}
    to: {
        _obj: "document",
        [property]: data
    _options: {dialogOptions: 'dontDisplay'}

When json didn’t work, I tried exact same descriptor to try saving XMP metadata described here by @simonhenke (just changed a bit to save it on document level), but still no luck - no error this time and BP returns some object with a bunch of methods (which I’m not sure how to test what it is):

But even then when I get XMPMetadataAsUTF8, my data that I tried to set is not there :frowning:

Any advice? What am I doing wrong?

Have you tried @DavideBarranca’s solution?:

1 Like

For whatever reason I didn’t notice this in search results (although topic name is so obvious). Thanks a lot. I’ll try this after work and let you know

Edit: Works like a charm :slight_smile: Kudos to @DavideBarranca also


Thanks! Waiting for a proper DOM way to deal with XMP :slight_smile: