Get the list of all attributes in a form using JavaScript

Avatar
Sep 24, 2019  1 min read

The following code snippet get the list of all attributes in a form

The below function show the list of all attributes in a dynamics 365 form:

function getAttributes(executionContext){
    var attributes = {};
    var formContext = executionContext.getFormContext();
    formContext.data.entity.attributes.forEach(
        function(attribute,index){
            var logicalName = attribute.getName();
            attributes[logicalName] = {
                'DisplayName':formContext.getControl(logicalName).getLabel(),
                'Type':attribute.getAttributeType(),
                'Value': attribute.getValue(),
                'IsDirty': attribute.getIsDirty(),
                'RequiredLevel': attribute.getRequiredLevel(),
                'IsDisabled' : formContext.getControl(logicalName).getDisabled(),
                'IsVisible' : formContext.getControl(logicalName).getVisible(),
            };
        }
    );
    console.table(attributes);
}


Note: The function not consider the fields in BPF, just take the fields presents in the form.


Open the browser console in order to see the result.

Comments
Be the first to comment.
Loading...