Search code examples
dynamics-crm

In Microsoft Dynamics CRM, how do I get the meaning of an attributemask value?


I have no background in Microsoft Dynamics CRM and the company I'm at lost their one developer who was maintaining this system. There is a function app with some code I'm trying to understand. The intent of the code appears to be to determine the user who set a price discount to then either permit it or not. It gets the audit entities associated with the salesorder that contain a 115 in the CSV AttributeMask.

List<Audit> audit = myServiceContext.AuditSet.Where(a => a.ObjectId.Id == x.Id)
    .ToList();

audit = audit.Where(a => a.AttributeMask.Split(',').ToList().Contains("115"))
    .ToList();

I believe this 115 must represent the discount field, but I want to know where the past developer found this value.

I've found suggestions online for how to get these AttributeMask values with a name, like this one, from the stringmap table. I used XrmToolBox's FetchXML Builder to dump the entire table but it only goes from 0 through 113. Some suggest looking in MetadataSchema tables, but I can't find those tables, and saw suggestions that those are only available for on-premises CRM.

Where can I find the meaning of 115 and/or how did a past developer decide to use this value?


Solution

  • The code queries the Audit table and selects the audit rows for the record identified by objectid. (This is the first line.) As you can read on MS Docs column audit.attributemetadata contains a CSV of the ColumnNumber metadata property of attributes.

    In the second line the audit rows are filtered down to those containing updates to column 115 of the table the targeted record belongs to. You can lookup the name and other properties of this column by retrieving the entity metadata for the table. The EntityMetadata object has an array of AttributeMetadata. In this array you can find the desired attribute by searching its column number in property ColumnNumber. More information can be found on MS Docs - AttributeMetadata.ColumnNumber Property.