locked
How to get the ID of a DataMap RRS feed

  • Question

  • Hi all,

    Does anybody know of any way to retrieve an Import DataMap from CRM 2011 (programmatically, i.e. using the SDK) without knowing its ID up front?

    I'm working on a re-usable Data Import application that does not want to re-import a DataMap into CRM if it already exists (because I'll get an error that it already exists). I know the name of the DataMap, but not the ID. Is there any way I can find out what the ID is, or get the DataMap using the name only, or delete an existing DataMap without kowning its ID? Or perhaps a way to retrieve a list of all (custom) DataMaps?

    Thanks in advance!

    Lucien Dol
    New Zealand.


    Lucien Dol QicSoluciens New Zealand

    Wednesday, March 28, 2012 2:04 AM

Answers

  • importmap is the entity you are looking for. Do a retrievemultiple on the name attribute of this entity and you should be able to get the Guid of the import map associated with the name.

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Wednesday, March 28, 2012 4:27 AM
    • Marked as answer by Lucien Dol Wednesday, March 28, 2012 9:51 PM
    Wednesday, March 28, 2012 4:27 AM

All replies

  • importmap is the entity you are looking for. Do a retrievemultiple on the name attribute of this entity and you should be able to get the Guid of the import map associated with the name.

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Wednesday, March 28, 2012 4:27 AM
    • Marked as answer by Lucien Dol Wednesday, March 28, 2012 9:51 PM
    Wednesday, March 28, 2012 4:27 AM
  • Thanks, Sam. That was what I was after. I didn't even consider checking to see if DataMaps were available as entities. Duh!

    Another question that you might know the answer to, if I may:

    How do I add a new field to an entity 'on the fly' using the SDK? Is that even posible?
    In this case I want to store the original ID in the migrated records so I can use that to link other entities back to.


    Lucien Dol QicSoluciens New Zealand

    Wednesday, March 28, 2012 9:55 PM
  • Yes you can create attributes programmatically using the SDK. Check out the CreateAttributeRequest in the SDK.

    Code snippet from the SDK

    // Create storage for new attributes being created
    addedAttributes = new List<AttributeMetadata>();

    // Create a boolean attribute
    BooleanAttributeMetadata boolAttribute = new BooleanAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_boolean",
        DisplayName = new Label("Sample Boolean", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Boolean Attribute", _languageCode),
        // Set extended properties
        OptionSet = new BooleanOptionSetMetadata(
            new OptionMetadata(new Label("True", _languageCode), 1),
            new OptionMetadata(new Label("False", _languageCode), 0)
            )
    };

    // Add to list
    addedAttributes.Add(boolAttribute);

    // Create a date time attribute
    DateTimeAttributeMetadata dtAttribute = new DateTimeAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_datetime",
        DisplayName = new Label("Sample DateTime", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("DateTime Attribute", _languageCode),
        // Set extended properties
        Format = DateTimeFormat.DateOnly,
        ImeMode = ImeMode.Disabled
    };

    // Add to list
    addedAttributes.Add(dtAttribute);

    // Create a decimal attribute   
    DecimalAttributeMetadata decimalAttribute = new DecimalAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_decimal",
        DisplayName = new Label("Sample Decimal", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Decimal Attribute", _languageCode),
        // Set extended properties
        MaxValue = 100,
        MinValue = 0,
        Precision = 1
    };

    // Add to list
    addedAttributes.Add(decimalAttribute);

    // Create a integer attribute   
    IntegerAttributeMetadata integerAttribute = new IntegerAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_integer",
        DisplayName = new Label("Sample Integer", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Integer Attribute", _languageCode),
        // Set extended properties
        Format = IntegerFormat.None,
        MaxValue = 100,
        MinValue = 0
    };

    // Add to list
    addedAttributes.Add(integerAttribute);

    // Create a memo attribute
    MemoAttributeMetadata memoAttribute = new MemoAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_memo",
        DisplayName = new Label("Sample Memo", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Memo Attribute", _languageCode),
        // Set extended properties
        Format = StringFormat.TextArea,
        ImeMode = ImeMode.Disabled,
        MaxLength = 500
    };

    // Add to list
    addedAttributes.Add(memoAttribute);

    // Create a money attribute   
    MoneyAttributeMetadata moneyAttribute = new MoneyAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_money",
        DisplayName = new Label("Money Picklist", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Money Attribue", _languageCode),
        // Set extended properties
        MaxValue = 1000.00,
        MinValue = 0.00,
        Precision = 1,
        PrecisionSource = 1,
        ImeMode = ImeMode.Disabled
    };

    // Add to list
    addedAttributes.Add(moneyAttribute);

    // Create a picklist attribute   
    PicklistAttributeMetadata pickListAttribute =
        new PicklistAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_picklist",
        DisplayName = new Label("Sample Picklist", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Picklist Attribute", _languageCode),
        // Set extended properties
        // Build local picklist options
        OptionSet = new OptionSetMetadata
            {
                IsGlobal = false,
                OptionSetType = OptionSetType.Picklist,
                Options =
            {
                new OptionMetadata(
                    new Label("Created", _languageCode), null),
                new OptionMetadata(
                    new Label("Updated", _languageCode), null),
                new OptionMetadata(
                    new Label("Deleted", _languageCode), null)
            }
            }
    };

    // Add to list
    addedAttributes.Add(pickListAttribute);

    // Create a string attribute
    StringAttributeMetadata stringAttribute = new StringAttributeMetadata
    {
        // Set base properties
        SchemaName = "new_string",
        DisplayName = new Label("Sample String", _languageCode),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("String Attribute", _languageCode),
        // Set extended properties
        MaxLength = 100
    };

    // Add to list
    addedAttributes.Add(stringAttribute);

    // NOTE: LookupAttributeMetadata cannot be created outside the context of a relationship.
    // Refer to the WorkWithRelationships.cs reference SDK sample for an example of this attribute type.

    // NOTE: StateAttributeMetadata and StatusAttributeMetadata cannot be created via the SDK.

    foreach (AttributeMetadata anAttribute in addedAttributes)
    {
        // Create the request.
        CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
        {
            EntityName = Contact.EntityLogicalName,
            Attribute = anAttribute
        };

        // Execute the request.
        _serviceProxy.Execute(createAttributeRequest);

        Console.WriteLine("Created the attribute {0}.", anAttribute.SchemaName);
    }

    HTH

    Sam


    Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Thursday, March 29, 2012 4:41 AM
    Thursday, March 29, 2012 4:41 AM