Skip to main content

Command Palette

Search for a command to run...

Update Attribute Metadata (file size) of File type field in Dynamics 365.

Updated
1 min read
S

Learning dynamics 365, Azure and Power Platform

After the file type field is created, the UI does not allow the size of the file type field to be updated., however, this can be done using the SDK.
UpdateAttributeRequest

Create a console application and run the below code to update the size of the file type field.

App.config

<connectionStrings>
    <add name="DataVerseConnection" connectionString="AuthType=ClientSecret;Url=https://org.crm8.dynamics.com;ClientId=6fd6aec2-0000-0000-0000-c99021cdc4ed;ClientSecret=0000~s1pTTBTbY1YZp9Td0000C0RUifBB9Bxxxx;"/>
  </connectionStrings>
public class UpdateFileAttributeMetaData
    {
        public static IOrganizationService _sourceservice;
        public static OrganizationServiceContext _sourcecontext;

       public static void Main(string[] args)
        {
            var sourceconnectionstring = ConfigurationManager.ConnectionStrings["DataVerseConnection"].ConnectionString;
            _sourceservice = GetServiceProxy(sourceconnectionstring);
            _sourcecontext = new OrganizationServiceContext(_sourceservice);

            FileAttributeMetadata fileColumn = new FileAttributeMetadata();
            fileColumn.SchemaName = "new_filetypefield";
            fileColumn.LogicalName = "new_filetypefield";
            fileColumn.DisplayName = new Label("Sample File Column", 1033);
            fileColumn.RequiredLevel = new AttributeRequiredLevelManagedProperty(
                AttributeRequiredLevel.ApplicationRequired);
            fileColumn.Description = new Label("Sample File Column updated", 1033);
            fileColumn.MaxSizeInKB = 80 * 1024; // 80 MB
            UpdateAttributeRequest updatefileColumnRequest = new UpdateAttributeRequest();
            updatefileColumnRequest.EntityName = "account";
            updatefileColumnRequest.Attribute = fileColumn;
            _sourcecontext.Execute(updatefileColumnRequest);
            Console.WriteLine("update success");
        }

        public static IOrganizationService GetServiceProxy(string connectionstring)
        {
            CrmServiceClient conn = new CrmServiceClient(connectionstring);
            if (conn.OrganizationServiceProxy != null)
                return conn.OrganizationServiceProxy;
            else
                return conn.OrganizationWebProxyClient;
        }
    }

File size before the update

File size after the update

Articles related to file type field :

https://beyondd365.dev/move-attachments-from-file-type-field-from-one-environment-to-another-in-dynamics-365

S

very informative and real time example..

1

More from this blog

Beyond D365

15 posts