locked
Heeelp with crmservice update RRS feed

  • Question

  •  Please help me!! I can't finish this plugin because of my update crm service.... please check where the error is... :(  Heeeelp!!  I want to assign to the attribute renewalmonth the value renewalsubtract, in my entity process, any idea????

    Thanks in advance

     

                  DynamicEntity entity3 = new DynamicEntity("process");

                    
                        CrmNumberProperty renewalmonth = new CrmNumberProperty();
                                             
                        renewalmonth.Name = "renewalmonth";
                        renewalmonth.Value = renewalsubtract;                        
                        entity3.Properties.Add(bre_renewalmonth);

                        // update the contact record
                       TargetUpdateDynamic updateDynamic = new TargetUpdateDynamic();
                        updateDynamic.Entity = entity3;

                       UpdateRequest request = new UpdateRequest();
                       request.Target = updateDynamic;

                       UpdateResponse response = (UpdateResponse)service.Execute(request);

     

    Friday, October 1, 2010 9:16 PM

Answers

  • Replace this code:

    CrmNumberProperty renewalmonth = new CrmNumberProperty();
    renewalmonth.Name = "renewalmonth";
    renewalmonth.Value = renewalsubtract;
    entity3.Properties.Add(renewalmonth);
    

    With this code:

    entity3.Properties.Add(new CrmNumberProperty("new_renewalmonth", renewalsubtract));
    
    This assumes that the variable renewalsubtract is of the type CrmNumber , which I assume from your assignment of it to the Value member of the CrmNumberProperty instance renewalmonth in your original code.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, October 2, 2010 12:26 AM
    Moderator

All replies

  • You need to supply the "id" of the record in order to update it.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, October 1, 2010 9:25 PM
    Moderator
  • Also, I'm sure the schema name of your custom entity is not simply "process", since CRM affixes a prefix to all custom entities and attributes.  By default, the prefix is "new_", so your entity's name would be "new_process" in that case.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, October 1, 2010 9:26 PM
    Moderator
  • ok, I have the ID now, but I dont know where to update it, can you give an example? yes, the entity is new_process, however the error is still there, so I need to know how to update the Id

     

    Thanks for your response

    Friday, October 1, 2010 9:54 PM
  • You need to add a KeyProperty instance to the Properties collection of your DynamicEntity, with its Value member set to a Key instance with the Guid instance--the value of which represents the record--assigned to the Key's Value member.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, October 1, 2010 10:18 PM
    Moderator
  • Something like this:

    entity3.Properties.Add(new KeyProperty("new_processid", new Key(entity3Guid)));
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, October 1, 2010 10:21 PM
    Moderator
  • now I get a new error...

     

      ICrmService service = (ICrmService)context.CreateCrmService(true);

                        //variable initialization
                        DynamicEntity entity3 = new DynamicEntity("new_process");

                          entity3.Properties.Add(new KeyProperty("new_processid", new Key(licenseeGuid)));

                        CrmNumberProperty renewalmonth = new CrmNumberProperty();
                        renewalmonth.Name = "renewalmonth";
                        renewalmonth.Value = renewalsubtract;
                        entity3.Properties.Add(renewalmonth);

                       
                        // update the contact record
                        TargetUpdateDynamic updateDynamic = new TargetUpdateDynamic();
                        updateDynamic.Entity = entity3;

                        UpdateRequest request = new UpdateRequest();
                        request.Target = updateDynamic;

                        UpdateResponse response = (UpdateResponse)service.Execute(request);

     

    Plugin error: "Server was unable to process request"

     Sorry, Im very new in CRM, please help me, what else I need to run my application???

     

    Friday, October 1, 2010 11:28 PM
  • You forgot to change "renewalmonth" to "new_renewalmonth".
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, October 2, 2010 12:04 AM
    Moderator
  • renewalmonth is the attribute where I need to store the value renewalsubtract, so, where do I have to change it to new_renewalmonth???
    Saturday, October 2, 2010 12:11 AM
  • Replace this code:

    CrmNumberProperty renewalmonth = new CrmNumberProperty();
    renewalmonth.Name = "renewalmonth";
    renewalmonth.Value = renewalsubtract;
    entity3.Properties.Add(renewalmonth);
    

    With this code:

    entity3.Properties.Add(new CrmNumberProperty("new_renewalmonth", renewalsubtract));
    
    This assumes that the variable renewalsubtract is of the type CrmNumber , which I assume from your assignment of it to the Value member of the CrmNumberProperty instance renewalmonth in your original code.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, October 2, 2010 12:26 AM
    Moderator
  • A good idea to hunt down the real error messages behind vague errors like "Server was unable to process request", is to enable tracing , and then probe the log files .
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, October 2, 2010 12:28 AM
    Moderator
  • Sorry, my code still doesn't run...

    Object reference not set to an instance of an object

    The property renewalmonth already exists in the CRM, then why I have to write: add new?? please, I can't finish this plugin...:(

    Monday, October 4, 2010 2:44 PM
  • If "renewalmonth" is an attribute of "new_process" then it must have "new_" as a prefix.  This is because it would be a "custom" attribute.  If "new_renewalmonth" is not an attribute for "new_process", then why would you be trying to update it?
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, October 4, 2010 3:26 PM
    Moderator
  • yes, it's an attribute, so why Iam geeting this error..

     

    Object reference not set to an instance of an object

    Monday, October 4, 2010 3:32 PM
  • That might require you to debug, but if your plugin is as simple as the code above, the solution should be easy.  The problem is, I have no understanding of where "renewalsubtract" or "licenseeGuid" come from or what their values are, and those could very well be the source of the problem.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, October 4, 2010 3:39 PM
    Moderator
  • My code is running!! yeah!! 

    Thank you very much for your help!!!

     

    :)

    Monday, October 4, 2010 5:51 PM
  • You're quite welcome.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, October 4, 2010 6:05 PM
    Moderator