none
How to access custom Account fields in plug-in code

    Question

  •  

    Hi!

     

    I've never written a plug-in for CRM before, but it seems straight forward with the documentation I have found so far. I've created a new class library project in VS2005 and added the CRM dll's. I want to run this plug-in when an Account is updated and check if a field I created for the Account entity (Sync) is set to true, then perform some actions. The new field is published and visible in the CRM interface, but it does not show up as a property of the account object in my code. Is there something I've missed? Is there some other way to get custom fields from an account object? Here is my code:

     

    Code Snippet

      //Execute
      public void Execute(IPluginExecutionContext context)
      {
       try
       {
        DynamicEntity entity = null;

        // Check whether the input parameters property bag contains a target
        // of the create operation and that target is of type DynamicEntity.
        if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
        {
         // Obtain the target business entity from the input parmameters.
         entity = (DynamicEntity)context.InputParameters.Properties["Target"];

         // Verify that the entity represents an account.
         if (entity.Name != EntityName.account.ToString()) { return; }
        }
        else
        {
         return;
        }
        
        //Cast to Account type
        account TargetAccount = (account) entity;
        
        
        

       }
       catch (Exception ex)
       {
        throw new InvalidPluginExecutionException("An unexpected exception occured when running the plug-in.", ex);
       }  
      }

     

     

     

    The TargetAccount object has all the other properties such as telephone number address etc, but not the field I created using the CRM interface.... Any ideas what I'm doing wrong here?

    Tuesday, April 08, 2008 1:59 PM

Answers

  • If you are using the Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy assemblies, which I assume you are, then you will need to use the DynamicEntity class for any custom attributes. The strongly-typed entity classes (like account) do not include any custom attributes

    Tuesday, April 08, 2008 5:35 PM
    Moderator

All replies

  • If you are using the Microsoft.Crm.Sdk and Microsoft.Crm.SdkTypeProxy assemblies, which I assume you are, then you will need to use the DynamicEntity class for any custom attributes. The strongly-typed entity classes (like account) do not include any custom attributes

    Tuesday, April 08, 2008 5:35 PM
    Moderator
  • Wednesday, April 09, 2008 12:56 PM
    Moderator
  •  

    Thanks for the help David, I think I've got that part figured out now. However I now have a new problem... Running the plugindeveloper project included in the SDK to register my plugin is not working. I have editet register.xml so it has the correct domain, user and server url (http://localhost:5555), however when it runs I am prompted for a password, then it waits a fem seconds and then it throws an 401 Unauthorized exception=( I know the password is correct, and the url is correct because if I change it it throws a 404 Not found exception instead... What am I missing?

     

    I am using the Administrator account here, so it should have the proper rights. I'm able to login to CRM with that account and do whatever I want. Is there some sort of special permission a user needs to register plug-ins?

     

    Update:

    Just confirmed that the administrator account is in fact part of the Deployment Administrators group in Deployment Manager...

     

    Yet another update:

    I just found out you have to have the Oranization name correct, so I found that in Deployment Manager (MicrosoftCRM) and put it in settings.xml but I'm still getting 401 Unauthorized... I've tried both "MicrosoftCRM" and "Microsoft CRM" to no effect...

    Thursday, April 10, 2008 11:32 AM