locked
How to update the field of a Parent enity (field is not visibe on the Form) from a Child Entity in MSCRM 2013 RRS feed

  • Question

  • Hi All,

              I m new to CRM customization. I have requirement like this..

    I have 3 entities.. Entity1 , Entity 2 and Entity3.

    Entity1 is the parent of Entity2 and Entity3. Entity2 is the parent of Entity3 and child of Entity1 ..

    In Entity1 I have a field eg:product1 which acts as lookup for Entity2 field availableproducts.  Now in Entity2 I have a field the quantity of products which acts as lookup for Entity3 as given below.

    In Entity3: fields:;; products==Lookup of Products(Entity1)

                                  quantity == Lookup of Quantity (Entity2)

    Now from Entity3 I need to update the fields of Entity1 like I have field named Price which is not visible on the Entity3 Form  but when I access this field from javascript I m getting null exceptions since the field is not in the context of the Entity on which it is defined. How can I update the fields of the Parent Entity1 from child Entity3  and also update the quantity field on Entity2 which are not avialable on the Entity3 Form.

    Any help is appreciated

    Waiting for the reply..


     


    FayazSyed

    Thursday, February 26, 2015 12:03 PM

All replies

  • If you want to use javascript and update related entity then you can do this using oData or Rest.

    Of the shelf using workflows you can update any attribute of parent entity. Therefore you can update any attribute of Entity 1 and Entity 2 from Entity 3 using workflow.

    If you are using CRM 2015 then also read about rollup field.


    Regards Faisal

    Thursday, February 26, 2015 12:30 PM
  • Hi Faisal ,

           Thanks for the reply. But I have requirement like this  I need to increment the field of parent Entity1 for examle I  have to increase the filed named items to 1 each time a record of child entity3 is created.This field items is not placed on the entity3. In workflow I don't find option to increase or decrease the record values of the parent entity1. I am currentlyworking on MS CRM 2013. Please help me how to proceed further.

    Regards,

    Fayaz.


    FayazSyed

    Thursday, February 26, 2015 2:06 PM
  • hi Fayaz,

    1. From your child entity, get the parent entity by using soap/rest query.

    2. Update the required fields from child entity.

    the above approach is best done on a synchronous plugin or workflow - otherwise you may run into concurrency issue.

    I would advise you create a plugin for this purpose, rather than JavaScript.

    regards

    Jithesh

    Thursday, February 26, 2015 10:12 PM
  • Hi,

    To do it in JS you need to use oData, as wrote above:

    to make this requests easer, i use a XrmSvcToolkit library (https://xrmsvctoolkit.codeplex.com/)

    Your code will be about this:

    /// <reference path="rtb_XrmSvcToolkit.js" />
    ....
    XrmSvcToolkit.retrieve({
        entityName: "Entity1",
        id: Xrm.Page.getAttribute("quantity").getValue()[0].id,
        select: ["my_FieldNeedToUpdate"], //Here are the name of your fields, which you want to select.
        expand: [""],
        async: false,
        successCallback: function (result) {
            FieldNeedToUpdate= result.my_FieldNeedToUpdate;
        },
        errorCallback: function (error) {
            Error = error;
        }
    });
    
    ...
    FieldNeedToUpdate = FieldNeedToUpdate + 1; //Doing some work here
    
    var InputEntity =
    {
       my_FieldNeedToUpdate: FieldNeedToUpdate //here are fields, witch you want to update
    }
    XrmSvcToolkit.updateRecord({
        entityName: "Entity1",
        id: Xrm.Page.getAttribute("quantity").getValue()[0].id,
        entity: InputEntity ,
        async: false
    });

    Here are more samples:

    https://xrmsvctoolkit.codeplex.com/SourceControl/latest#Samples/XrvSvcToolkit.Samples.updateRecord.js

    • Edited by xjomanx Friday, February 27, 2015 6:55 AM
    Friday, February 27, 2015 6:52 AM