Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

how to create an entity from an xml file in crm 365

(0) ShareShare
ReportReport
Posted on by
I have an xml of a CRM 3.0 personal entity (with all its fields, etc), what I want to do an import into the Dynamics 365 CRM.
As far as I was reading, there is not an import, but an intermediate process of coding (C #) that reads the entity and its fields, and inserts them in that way to the Dynamics 365 CRM
Could someone support me with the process?

*This post is locked for comments

  • RE: how to create an entity from an xml file in crm 365

    There are several personalized entities and I would like to know how to do that process

  • RE: how to create an entity from an xml file in crm 365

    Could you tell me as examples what are the input parameters of the method

    public void CreateAttribute (atributo AttributeMetadata, cadena targetEntity)

    {...}

  • Suggested answer
    Flydancer Profile Picture
    Flydancer 1,332 on at
    RE: how to create an entity from an xml file in crm 365

    You have to read the entity metadata from your XML one by one and create the corresponding entities/fields.

    See here how to creaty an entity programatically: docs.microsoft.com/.../sample-create-update-entity-metadata

    Here are a few snippets to create attributes(fields) from one of my projects that could save you some time:

            public void CreateAttribute(AttributeMetadata attribute, string targetEntity)
            {
                dynamic newattribute = null;
    
                switch (attribute.AttributeType.Value)
                {
                    case AttributeTypeCode.Boolean:
                        newattribute = CreateBoolAttribute(attribute);
                        break;
                    case AttributeTypeCode.DateTime:
                        newattribute = CreateDateTimeAttribute(attribute);
                        break;
                    case AttributeTypeCode.Decimal:
                        newattribute = CreateDecimalAttribute(attribute);
                        break;
                    case AttributeTypeCode.Integer:
                        newattribute = CreateIntegerAttribute(attribute);
                        break;
                    case AttributeTypeCode.String:
                        newattribute = CreateStringAttribute(attribute);
                        break;
                    case AttributeTypeCode.Picklist:
                        newattribute = CreatePickListAttribute(attribute);
                        break;
                    case AttributeTypeCode.Memo:
                        newattribute = CreateMemoAttribute(attribute);
                        break;
                    case AttributeTypeCode.Money:
                        newattribute = CreateMoneyAttribute(attribute);
                        break;
                    default:
                        break;
                }
    
                if (newattribute != null)
                {
                    CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
                    {
                        EntityName = string.IsNullOrEmpty(targetEntity) ? attribute.EntityLogicalName : targetEntity,
                        Attribute = newattribute
                    };
                    Service.Execute(createAttributeRequest);
                }
            }
    
            private MoneyAttributeMetadata CreateMoneyAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (MoneyAttributeMetadata)oldattribute;
    
                MoneyAttributeMetadata moneyAttribute = new MoneyAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    ImeMode = attribute.ImeMode,
                    MaxValue = attribute.MaxValue,
                    MinValue = attribute.MinValue,
                    Precision = attribute.Precision,
                    PrecisionSource = attribute.PrecisionSource
    
                };
                return moneyAttribute;
            }
    
            private MemoAttributeMetadata CreateMemoAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (MemoAttributeMetadata)oldattribute;
    
                MemoAttributeMetadata memoAttribute = new MemoAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    Format = StringFormat.TextArea,
                    ImeMode = attribute.ImeMode,
                    MaxLength = attribute.MaxLength
    
                };
                return memoAttribute;
            }
    
            private PicklistAttributeMetadata CreatePickListAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (PicklistAttributeMetadata)oldattribute;
    
                PicklistAttributeMetadata picklistAttribute = new PicklistAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    OptionSet = attribute.OptionSet,
                    DefaultFormValue = attribute.DefaultFormValue
    
                };
                return picklistAttribute;
            }
    
            private StringAttributeMetadata CreateStringAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (StringAttributeMetadata)oldattribute;
    
                StringAttributeMetadata stringAttribute = new StringAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    Format = attribute.Format,
                    ImeMode = attribute.ImeMode,
                    MaxLength = attribute.MaxLength
                    
                };
                return stringAttribute;
            }
    
            private IntegerAttributeMetadata CreateIntegerAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (IntegerAttributeMetadata)oldattribute;
    
                IntegerAttributeMetadata integerAttribute = new IntegerAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    Format = attribute.Format,
                    MaxValue = attribute.MaxValue,
                    MinValue = attribute.MinValue
                };
                return integerAttribute;
            }
            
            private DecimalAttributeMetadata CreateDecimalAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (DecimalAttributeMetadata)oldattribute;
    
                DecimalAttributeMetadata decimalAttribute = new DecimalAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    MaxValue = attribute.MaxValue,
                    MinValue = attribute.MinValue,
                    Precision = attribute.Precision
                };
                return decimalAttribute;
            }
    
            private DateTimeAttributeMetadata CreateDateTimeAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (DateTimeAttributeMetadata)oldattribute;
    
                DateTimeAttributeMetadata dtAttribute = new DateTimeAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    Format = attribute.Format,
                    ImeMode = attribute.ImeMode
                };
                return dtAttribute;
            }
    
            private BooleanAttributeMetadata CreateBoolAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (BooleanAttributeMetadata)oldattribute;
    
                BooleanAttributeMetadata boolAttribute = new BooleanAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    OptionSet = attribute.OptionSet
                };
                return boolAttribute;
            }
    
            private LookupAttributeMetadata CreateLookupAttribute(AttributeMetadata oldattribute)
            {
                var attribute = (LookupAttributeMetadata)oldattribute;
    
                LookupAttributeMetadata lookupAttribute = new LookupAttributeMetadata
                {
                    LogicalName = attribute.LogicalName,
                    SchemaName = attribute.LogicalName,
                    DisplayName = attribute.DisplayName,
                    RequiredLevel = attribute.RequiredLevel,
                    Description = attribute.Description,
                    Targets = attribute.Targets,
                    IsValidForAdvancedFind = attribute.IsValidForAdvancedFind,
                    SourceType = attribute.SourceType
                };
                return lookupAttribute;
            }
  • Kokulan Profile Picture
    Kokulan 18,052 on at
    RE: how to create an entity from an xml file in crm 365

    How many entities you have? is it just one entity or more ? Are you planning to import data as well?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans