I used Batchplay to change the XMP of a document ,But there was no way to modify it successfully
1 Like
Did you try logging the batchPlay
result or any errors in a try catch?
Also, what’s the before/after of the Metadata and how does your xmpString look like?
import { convert} from 'xmlbuilder2';
function getDocumentXMPMeta(docId,xmpString){
const res = await batchPlay([ {
_obj: 'get',
_target: [
{
_ref: 'document',
_id: documentID,
_property: 'XMPMetadataAsUTF8',
},
],
_options: {
dialogOptions: 'dontDisplay',
},
}], {
});
return res[0]?.XMPMetadataAsUTF8 || '';
}
function setDocumentXMPMeta(docId,xmpString){
const res = await batchPlay([ {
_obj: 'set',
_target: [
{
_ref: 'document',
_id: docId,
_property: 'XMPMetadataAsUTF8',
},
],
to: {
_obj: 'document',
XMPMetadataAsUTF8: xmpString,
},
}], {
});
return res[0]?.XMPMetadataAsUTF8 || '';
}
function setMetaXmp(docId){
const xmpString = await getDocumentXMPMeta(docId);
const obj = convert(xmpString, { format: 'object' });
obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][`@xmlns:${123}`] = 'test1';
obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][`${'xml'}:${456}`] = 'test2';
const newXmpString = convert(obj, { format: 'xml' });
await setDocumentXMPMeta(docId, newXmpString);
const newString = await getDocumentXMPMeta(docId);
console.log('oldXml',xmpString) //old xmp
console.log('newXml',newString) // new xmp
}
setMetaXmo(1); // execute
I’m transferring the XML:
But I got a new one:
this fails to modify xmp