locked
Update and assign value RRS feed

  • Question

  • Hi  have a problem with Update fields, I need to store the result of the operation into the fieldFinal field, but I dont know why is not getting the value in the database.. Evrything is ok but I cant asign the value into the database.

     

     

     

     <Image EntityAlias="PostOperation"

    ImageType="1"

    MessagePropertyName="Target"

    Attributes="field1, field2, fieldFinal"

    />

    </Images>

     

    CODE
                    DynamicEntity PostLicenseeEntity = null;

     if (context.PostEntityImages.Properties.Contains("PostOperation") && context.PostEntityImages.Properties["PostOperation"] is
                    DynamicEntity)
                    {


                        PostOperation= (DynamicEntity)context.PostEntityImages.Properties["PostOperation"];


                    }

     if (PostOperation.Properties.Contains("fieldFinal") == true)


                            {
                                ((CrmNumberProperty)PostOperation.Properties["fieldFinal"]).Value = new CrmNumber(renewalsubtract);

                            }

     

     

     

    I already debug and I got the renewalsubtract into my code, even when I put a breakpoint in the last line, I can read the renewalsubtract value, the plugin ends, but the value is not asigned to fieldFinal field in the database..... What do I need???

     

    Thanks in advance

     

     

     

    Thursday, September 30, 2010 9:18 PM

Answers

  • so after retrieving the values from Images and once I get the renewalsubtract value, I could use this value into Update method of CRM Service???

    can you explain me that, please??

    This is correct. Images can be used only for getting the data. Update method can be used to update data in CRM.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Friday, October 1, 2010 4:49 AM
    Moderator
  • Hi,

    First get the current record guid : see below code:
    Guid CourtCaseGuid = ((Lookup)((DynamicEntity)context.InputParameters.Properties["Target"]).Properties["new_courtcaseid"]).Value;

    Once your get the Guid, retrieve the entity record: See below Code

    string[] retrieveColumnList = new string[] { "attribute_to_update" };

                    // Create the retrieve target.
                    TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

                    // Set the properties of the target.
                    targetRetrieve.EntityName = strEntityName;
                    targetRetrieve.EntityId = EntityGuid;

                    // Create the request object. // Set the properties of the request object.
                    RetrieveRequest retrieve = new RetrieveRequest();
                    retrieve.Target = targetRetrieve;

                   ColumnSet Cols = new ColumnSet();
                        Cols.AddColumns(retrieveColumnList);
                        retrieve.ColumnSet = Cols;

                    // Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
                    retrieve.ReturnDynamicEntities = true;

                    // Execute the request.
                    RetrieveResponse retrieved = (RetrieveResponse)Service.Execute(retrieve);

                    // Extract the DynamicEntity from the request.
                    DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;

    if Dyanmic entity object is not null and has the attribue in it, then assign th value to the attribute and upate it.

    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, October 2, 2010 5:30 AM

All replies

  • Images are used only for data retrieving. To update record you should use Update method of CRM Service.
    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, September 30, 2010 9:28 PM
    Moderator
  • so after retrieving the values from Images and once I get the renewalsubtract value, I could use this value into Update method of CRM Service???

    can you explain me that, please??

    Thursday, September 30, 2010 9:56 PM
  • so after retrieving the values from Images and once I get the renewalsubtract value, I could use this value into Update method of CRM Service???

    can you explain me that, please??

    This is correct. Images can be used only for getting the data. Update method can be used to update data in CRM.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Friday, October 1, 2010 4:49 AM
    Moderator
  • what you have to do is, just pass the value to the current entity, i mean add your attribute to the property bag with the attribute and value pair.

    thats it. then the crm will take care of it.

    if you want in depth let me know.

     

    Sudhanshu

    Friday, October 1, 2010 8:44 AM
  • Thanks for your answer,..may you help me? I dont know how to pass the value to the current entity.. :(  please give an example..

    Best regards,

    Friday, October 1, 2010 2:17 PM
  • Hi,

    First get the current record guid : see below code:
    Guid CourtCaseGuid = ((Lookup)((DynamicEntity)context.InputParameters.Properties["Target"]).Properties["new_courtcaseid"]).Value;

    Once your get the Guid, retrieve the entity record: See below Code

    string[] retrieveColumnList = new string[] { "attribute_to_update" };

                    // Create the retrieve target.
                    TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

                    // Set the properties of the target.
                    targetRetrieve.EntityName = strEntityName;
                    targetRetrieve.EntityId = EntityGuid;

                    // Create the request object. // Set the properties of the request object.
                    RetrieveRequest retrieve = new RetrieveRequest();
                    retrieve.Target = targetRetrieve;

                   ColumnSet Cols = new ColumnSet();
                        Cols.AddColumns(retrieveColumnList);
                        retrieve.ColumnSet = Cols;

                    // Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
                    retrieve.ReturnDynamicEntities = true;

                    // Execute the request.
                    RetrieveResponse retrieved = (RetrieveResponse)Service.Execute(retrieve);

                    // Extract the DynamicEntity from the request.
                    DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;

    if Dyanmic entity object is not null and has the attribue in it, then assign th value to the attribute and upate it.

    Hope this helps.


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, October 2, 2010 5:30 AM
  • try the samlpe given by Ranjit.

    else follow the sdk for more.

     

    Sudhanshu

    Saturday, October 2, 2010 6:52 AM