Reproduction Steps:
-
Create a field with field level security enabled for a record.
-
Create a field security profile for full access to that field.
-
Add the current user to that field security profile
-
Attempt to create a record (This should work).
-
Add auto number attributes to the newly created field using the XRM toolbox add-in.
-
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.”
- 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);
}
}
Reproduction Steps:
Create a field with field level security enabled for a record.
Create a field security profile for full access to that field.
Add the current user to that field security profile
Attempt to create a record (This should work).
Add auto number attributes to the newly created field using the XRM toolbox add-in.
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.”
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.