Adding record assignments

Records in the data domain can be updated with one or more new assignments for standard attributes and managed values.

The updateRecords sub-operation, when used with a list of addAssignments elements, allows you to update existing records in the data domain by adding standard attribute values and/or managed values. The element can also create a standard or managed attribute if the attribute to be added does not exist. In this case, it is added with the default values for PDRs.

Because the Dgraph process performs type-checking when adding standard attributes, keep the following in mind:
  • When adding a value for a pre-existing standard attribute, make sure that the new value is of the proper type. An error will occur for type mismatches (for example, if you attempt to assign the string "red" to an integer standard attribute).
  • When creating and adding a new standard attribute, you should specify the attribute type.
  • Any standard attribute that is not specifically typed will be treated by default as a string type.

You can assign multiple values from a given standard attribute only if the attribute is configured as a multi-assign standard attribute. That means that the PDR for the standard attribute has the mdex-property_IsSingleAssign property set to true. If the addAssignments list attempts to assign multiple values to a standard attribute that does not accept multiple values, an error is signaled.

Managed values can be added to records even if the managed attribute to which they belong does not exist in the data domain. In this case, the Data Ingest Web Service automatically creates the managed attribute.

Update sub-operation types

For update scenarios, the ingestChanges operation has two update sub-operations that support the addAssignments element. Which one you use depends on your needs:
  • The updateRecords sub-operation can only update existing records, but cannot add new records. That is, if the specified primary key is not found, then the operation does nothing.
  • The addOrUpdateRecords sub-operation will first attempt to update existing records, just like the updateRecords sub-operation. But if the specified primary key is not found, then the operation's fallback behavior is to act like the addRecords sub-operation and create new records based on the values of the specified primary keys and added assignment values.

This chapter will document the updateRecords sub-operation. For a description of addOrUpdateRecords, see Adding records after the initial load.

updateRecords request

You use the addAssignments element in an updateRecords request to add key-value pairs to an existing record. The request must specify the primary key of the record to be updated, using this request format:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:ns="http://www.endeca.com/MDEX/ingest/2/0" 
   xmlns:ns1="http://www.endeca.com/MDEX/XQuery/2009/09">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:ingestChanges>
         <ns:updateRecords>
            <ns:recordSpecifier>?</ns:recordSpecifier>
              <ns:addAssignments>
              <ns1:attribute name="?">?</ns1:attribute>
            </ns:addAssignments>
           </ns:updateRecords>
       </ns:ingestChanges>
   </soapenv:Body>
</soapenv:Envelope>
For example, this updateRecords request updates a record (with the primary key P123) with one standard attribute modelNum of type integer:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:ns="http://www.endeca.com/MDEX/ingest/2/0" 
  xmlns:ns1="http://www.endeca.com/MDEX/XQuery/2009/09">
  <soapenv:Header/>
   <soapenv:Body>
      <ns:ingestChanges>
        <ns:updateRecords>
          <ns:recordSpecifier>"partID" = 'P123'</ns:recordSpecifier>
              <ns:addAssignments>
              <ns1:attribute name="modelNum" type="mdex:int">2562</ns1:attribute>
            </ns:addAssignments>
         </ns:updateRecords> 
       </ns:ingestChanges>
   </soapenv:Body>
</soapenv:Envelope>

Note that the attribute type of the modelNum standard attribute is specified, because the standard attribute does not exist and therefore will be created as part of the request.

Note: If you submit the ingestChanges request after a Transaction Web Service request that starts an outer transaction, the request must specify the outer transaction ID. If no outer transactions have been started, the ID attribute must be omitted in the request.