Update or add metadata properties satisfying a predicate
The setProperties method used in this code sample actually combines two operations: add and update. If an existing property satisfies the specified predicate its value is updated. If there is a known property missing in a metadata package that satisfies the predicate it is added to the appropriate package.
The code snippet below demonstrates a basic usage scenario of the setProperties method.
Open a file to update
Specify a predicate that will be used to add/update metadata properties
Specify a value you would like to add to existing metadata packages in the file
Check the actual number of added/updated properties
Save the changes
basic_usage.SetMetadataProperties
constmetadata=newgroupdocs.metadata.Metadata("input.vsdx");// Set the value of each property that satisfies the predicate:
// property contains the date/time the document was created OR modified
varaffected=metadata.setProperties(newgroupdocs.metadata.ContainsTagSpecification(groupdocs.metadata.Tags.getTime().getCreated()).or(newgroupdocs.metadata.ContainsTagSpecification(groupdocs.metadata.Tags.getTime().getModified())),newgroupdocs.metadata.PropertyValue(newDate()));console.log(`Properties set: ${affected}`);metadata.save("output.vsdx");
As a result, we update all existing metadata properties containing the date the document was created/updated. If a metadata package doesn’t contain such properties but they are meant to be in its structure they are added.
For more information on supported features of the GroupDocs.Metadata search engine please refer to the following articles: