Skip to content

When adding auto number attributes to an existing field with field level security some meta data is removed and the fields permissions break #18

@aidanoleary

Description

@aidanoleary

Reproduction Steps:

  1. Create a field with field level security enabled for a record.

  2. Create a field security profile for full access to that field.

  3. Add the current user to that field security profile

  4. Attempt to create a record (This should work).

  5. Add auto number attributes to the newly created field using the XRM toolbox add-in.

  6. Attempt to create another record. This time the following error will occur:

“The user does not have create permissions to a secured field. The requested operation could not be completed. If you contact support, please provide the technical details.”

  1. The field also disappears from the list of fields that have field level security enabled on.

Notes:
I believe the issue is caused by not retrieving the existing attribute metadata before calling the update attribute request.

I don't encounter the same problem when using the following code from a console application.

        private static void AddAutoNumberToExistingField(string entityName, string fieldName, string autoNumberFormat, int seedValue = 0)
        {
            // Create the retrieve request
            RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName = entityName,
                LogicalName = fieldName,
                RetrieveAsIfPublished = true
            };
            // Retrieve attribute response
            RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)_client.Execute(attributeRequest);

            //Modify the retrieved auto-number attribute
            AttributeMetadata retrievedAttributeMetadata = attributeResponse.AttributeMetadata;
            retrievedAttributeMetadata.AutoNumberFormat = autoNumberFormat; //Modify the existing attribute by writing the format as per your requirement 

            // Update the auto-number attribute            
            UpdateAttributeRequest updateRequest = new UpdateAttributeRequest
            {
                Attribute = retrievedAttributeMetadata,
                EntityName = entityName
            };
            // Execute the update attribute request
            _client.Execute(updateRequest);

            if (seedValue > 0)
            {
                // Set the auto number seed value
                SetAutoNumberSeedRequest setSeedValueRequest = new SetAutoNumberSeedRequest();
                setSeedValueRequest.EntityName = entityName;
                setSeedValueRequest.AttributeName = fieldName;
                setSeedValueRequest.Value = seedValue;
                _client.Execute(setSeedValueRequest);
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions