You are here

You are here

Accessing and Updating Attributes

An SCMDocument object contains a property called Metadata, which is an array of SCMMetadata objects.  The array contains one object in the array for every attribute field on the document.  In the case of repeating fields and repeating sets, the SetNumber property on the SCMMetadata object will be populated to link fields of the same set together. 

The SCMMetadata objects contain group, field and value properties that can be read by the web services client.  Addtionally, the existing metadata objects can be updated and/or new metadata objects can be added to the array in the case where the custom attributes need to be updated on the document. If changes are made to the Metadata array, the parent SCMDocument object must be passed to the DocumentSave method to commit the change to SpringCM.  The core SCMDocument properties such as Name and Description may be updated in this manner as well.

Vertical Tabs

c#
//If we want to update existing metadata, we would return true for the third parameter here
//to have the API return the existing metadata array.  We could then loop through the array and make 
//updates as well as well as additions.
string documentId = "<Source document Id retrieved by other method calls>";
var contractDoc = springCMService.DocumentGetById(token,documentId, true);
 
//In this sample, we have a group called "Contracts" and we want to update
//the Status field to a value of "Complete"
//We use the foundField boolean to track if we need to make an addition
bool statusUpdated = false;
 
if (contractDoc.Metadata != null)
{
   //Find the Status field in the Contracts group
   foreach (SCMMetadata metadata in contractDoc.Metadata)
   {
	   if (metadata.GroupName == "Contracts" &&
		   metadata.FieldName == "Status")
	   {
		   Console.WriteLine("Found contract status of {0}, changing to Complete", metadata.Value);
		   metadata.Value = "Complete";
		   statusUpdated = true;
	   }
   }
}
 
//If we didn't find and update an existing status
//we can just create a new array and add it to the document
//This will not delete any existing fields, it will just add the new one
if (!statusUpdated)
{
   contractDoc.Metadata = new List<SCMMetadata>
          {
              new SCMMetadata
	      {
		 GroupName = "Contracts",
		 FieldName = "Status",
		 Value = "Complete"
	      }
	 }.ToArray();
}
 
//We can make other changes such as description
contractDoc.Description = "Completed Contract";
 
//Now save the document to commit the change to SpringCM
springCMService.DocumentSave(token, contractDoc);
java
//If we want to update existing metadata, we would return true for the third parameter here
//to have the API return the existing metadata array.  We could then loop through the array and make 
//updates as well as well as additions.
String documentId = "<Source document Id retrieved by other method calls>";
SCMDocument contractDoc = springCMService.documentGetById(token,documentId, true);
 
//In this sample, we have a group called "Contracts" and we want to update
//the Status field to a value of "Complete"
//We use the foundField boolean to track if we need to make an addition
boolean statusUpdated = false;
 
if (contractDoc.getMetadata() != null)
{
 //Find the Status field in the Contracts group
 for(SCMMetadata metadata : contractDoc.getMetadata())
 {
	 if (metadata.getGroupName().equals("Contracts") &&
		 metadata.getFieldName().equals("Status"))
	 {
		 System.out.format("Found contract status of %s, changing to Complete\n", metadata.getValue());
		 metadata.setValue("Complete");
		 statusUpdated = true;
	 }
 }
}
 
//If we didn't find and update an existing status
//we can just create a new array and add it to the document
//This will not delete any existing fields, it will just add the new one
if (!statusUpdated)
{
 SCMMetadata metadata = new SCMMetadata();
 metadata.setGroupName("Contracts");
 metadata.setFieldName("Status");
 metadata.setValue("Complete");
 metadata.setDataType(SCMMetadataValueType.String);
 
 SCMMetadata[] m = new SCMMetadata[]{metadata};
 contractDoc.setMetadata(m);
}
 
//We can make other changes such as description
contractDoc.setDescription("Completed Contract");
 
//Now save the document to commit the change to SpringCM
springCMService.documentSave(token, contractDoc);
php
<?php
 
// A SpringCM custom menu item puts the selected items on the query string in the format // Selection=Document,<document id>;
// The document's ID will be needed later so we remove the labeling here
//This sample shows the updates being made in the context from a SpringCM custom menu item, however the metadata update code would apply in any context,
//only the authentication and selection code would change
$document = str_replace('Document,', '', $_GET['Selection']);
$document = rtrim($document, ';');
 
// Adding the User Key to the query string puts two parameters in the URL: the user's email and a generated user key
$user_id  = $_GET['uEmail'];
$user_key = $_GET['userkey'];
 
// Get a SpringCM session using AuthenticateWithKeys
$springcm = new SoapClient("
https://soapna11.springcm.com/atlas/webservices/v201305/springcmservice.asmx?wsdl");
 
$auth_result = $springcm->AuthenticateWithKeys( array (
	'userName'=>$user_id,
	'userKey'=>$user_key,
	'apiKey'=>'<your api key>' ));
 
// The AuthenticateWithKeysResult is a wrapper around the token
$token = $auth_result->AuthenticateWithKeysResult; 
 
// First call DocumentGetById to retrieve the document with its metadata. 
// Make sure loadExtendedMetadata is set to true
$scm_doc = $springcm->DocumentGetById( array (
	'token'=>$token,
	'documentId'=>$document,
	'loadExtendedMetadata'=>true ));
 
// There's an outer wrapper on the returned object; need to get inside it
$scm_doc = $scm_doc->DocumentGetByIdResult;
 
// Get an array containing all the document's metadata
$all_metadata = $scm_doc->Metadata->SCMMetadata;
 
// To get a specific value from metadata, loop through the array until 
// we find the matching group and field name
$lookup_value = '';
foreach ($all_metadata as $search_metadata)
{
	if ($search_metadata->GroupName == 'Key Group Name'
       and $search_metadata->FieldName == 'Key Field Name')
	{
		$lookup_value = $search_metadata->Value;
		break;
	}
}
unset($search_metadata);
 
echo "Key Group Name.Key Field Name: $lookup_value";
 
// Here we search for an existing metadata value and update it...
foreach ($all_metadataas$update_metadata)
{
	if ($update_metadata->GroupName == 'Update Group Name'
       and $update_metadata->FieldName == 'Update Field Name')
	{
		$update_metadata->Value = '<new value>';
		break;
	}
}
unset ($update_metadata);
 
// ...and here we add a new value to the document's metadata
$new_metadata = new stdClass();
$new_metadata->GroupName = 'New Group Name';
$new_metadata->FieldName = 'New Field Name';
$new_metadata->Value = '<value to be added>';
$new_metadata->ExcludeFromSearch = false;
$new_metadata->DataType = 'String';
 
// Once the new metadata object is created, it must be pushed directly onto the 
// Metadata->SCMMetadata array on the SCMDocument object. 
// Pushing it onto $all_metadata does not work.
array_push($scm_doc->Metadata->SCMMetadata, $new_metadata);
 
// To complete the metadata update, call DocumentSave with the updated SCMDocument object
$springcm->DocumentSave( array (
	'token'=>$token,
	'scmDocument'=>$scm_doc ));
 
echo 'Document updated.'
 
?>