Is there a way to properly set an attribute value on an object in Communications cloud? Assume we've got an attribute called 'Color' on the Product2 object. As for now, I only see the option to set the JSON string value directly to the vlocity_cmt__JSONAttribute__c field, but this doesn't seem right as there are some encoded values in the JSON which I can't find the source of.
1 Answer
In Vlocity, the attribute values linked to any object are stored as Attribute Assignment records. Whenever we link a certain attribute to some object, behind the scenes an Attribute Assignment record is created. Here’s a brief overview of some of the significant fields on Attribute Assignment object.
NOTE : API names mentioned below are with respect to Vlocity CMT package
Attribute : ID of the Vlocity Attribute assigned to the parent object. API Name of this field is vlocity_cmt__AttributeId__c. This is a Lookup field.
Assigned To Object Id : ID of the parent object to which the attribute is assigned. API Name of this field is vlocity_cmt__ObjectId__c. This is a Text field.
Assigned To Object Name : Type of sObject to which this attribute is assigned. API Name of this field is vlocity_cmt__ObjectType__c. This is a Text field.
Value : Value of this attribute. For example, attribute strength (0–5), or a text value “Jimmy”. API Name of this field is vlocity_cmt__Value__c. This is Text field.
Value Data Type : Data type of this attribute such as text, number, percent or checkbox. Overrides the Value Type field on the assigned Vlocity Attribute. API Name of this field is vlocity_cmt__ValueDataType__c. This is a Picklist field.
Following is a code snippet where I am updating Attribute Assignment records for a Product record having record Id : 01t5i0000072GeQAAU in my trial org.
//Fetching the Attribute Assignment records using Object Id
List<vlocity_cmt__AttributeAssignment__c> assignmentList = [SELECT Id FROM vlocity_cmt__AttributeAssignment__c WHERE vlocity_cmt__ObjectId__c = '01t5i0000072GeQAAU'];
//Iterating over Attribute Assignment records
for(vlocity_cmt__AttributeAssignment__c assignment: assignmentList){
//Updating attribute assignment value
assignment.vlocity_cmt__Value__c = 'New Value';
//Updating attribute assignment data type
assignment.vlocity_cmt__ValueDataType__c = 'Text';
}
//Updating Attribute Assignment records
update assignmentList;
For further explanation on Attribute Assignment and related objects, you can refer the following link :
https://medium.com/@rawatswapnil911/understanding-the-vlocity-attribute-data-model-743256dc27f4