คำตอบ query a field from another entity

  • 12 พฤศจิกายน 2551 18:40
     
     
    hi guys,

    im new to ms crm. its a great and poweful tool. after some experience i have some questions. i have two formulars

    new_formA (form A)
    ----------------------
    new_attribute1 (nvchar)

    new_formB (form B)
    ----------------------
    new_attribute2
    new_attribute3 (nvchar)


    new_attribute3 is a autofill field and contain with value-of new_attribute1 from form A. i attached a image showing what it should look like: http://img177.imagevenue.com/img.php?image=15163_mscrm_122_580lo.jpg

    ive already tried something like this, but it doesnt work:



    ///////////////
    var lookupData = new Array();
    var lookupItem = new Object();

    lookupData = crmForm.all.new_attribute2.DataValue;
    lookupItem = lookupData[0];

    var ident = lookupItem.id;
    var name = lookupItem.name;
    var typename = lookupItem.typename;


    crmForm.all.new_attribute3.DataValue = lookupItem;
    ///////////////


    new_attribute1 is somewhere missed. can anyone help me? thanks Smile regards

    ps: sry for my english.



ตอบทั้งหมด

  • 13 พฤศจิกายน 2551 4:53
     
     

    Hi,

     So you have 2 entities A and B.

    new_attribute1 is in entity A

    new_attribute2 is a lookup field in the entity B which shows the entity A, right?

    When you select an item in the new_attribute2 lookup, you need to autofill the new_attribute3,right?

    And the autofill value(new_attribite3) should be an another column value of the selected item in the new_attribute2 lookup,right?

    If yes, try this code in the onchange event of new_attribute2 lookup.

     

    var lookup1= crmForm.all.new_attribute2;
    if( lookup1.DataValue != null )
    {
    var lookupColumns = lookup1.items[0].keyValues;
    crmForm.all.new_attribute3.value=lookupColumns.new_corresponding_fieldname_of_the_lookup.value;
    }

     

  • 13 พฤศจิกายน 2551 10:28
     
     

     

    Hi Krishna Raj.R,

     

    thanks for your help. you get the point.

     

    but it doesnt work for me (rookie ^^). i dont know why. what do you mean with "new_corresponding_fieldname_of_the_lookup"? should i add your code between my code? thx Wink

     

     

  • 13 พฤศจิกายน 2551 11:15
     
     

     

    Hi,

    No!

    I mean, in the place of "new_corresponding_fieldname_of_the_lookup", u just add ur attribute name for that corresponding attribute of ur entity A.

    ie, Which attribute value in Entity A should you need to autofill in the attribute3 in entity B, u just use that attribute's name in the code.

    Simple...Smile

  • 13 พฤศจิกายน 2551 11:55
     
     

    thats it what ive done:

     

     

    var lookup1 = crmForm.all.new_attribute2.DataValue;
    if( lookup1.DataValue != null )
    {
    var lookupColumns = lookup1.items[0].keyValues;
    crmForm.all.new_attribute3.Value = lookupColumns.new_attribute1.Value;
    }

     

    where in the code the entity_B knows, that new_attribute1 is in entity_A?

  • 13 พฤศจิกายน 2551 12:46
     
     

    Hi,

    Please answer to these questions.. Smile

    1.Did u understand what is in this code?

       var lookup1 = crmForm.all.new_attribute2.DataValue;

    2.Is the new_attribute2 a lookup field and is related to Entity A ?

       If so, Now the lookup1 will contains the Entity A records.

    3.Which attribute's value in Entity A is filled in new_attribute2 ?

    4.Which attribute's value in Entity A is needed for u to autofill in new_attribute3 ? use that attribute's name in the place  of"new_attribute1" in the above code.

     

  • 13 พฤศจิกายน 2551 14:09
     
     

    first of all many thanks for your help :-)

     

     

    1.Did u understand what is in this code?
    var lookup1 = crmForm.all.new_attribute2.DataValue;
    ---------------------------------------
    a variable named "lookup1" is filled with content of "new_attribute2".


    2.Is the new_attribute2 a lookup field and is related to Entity A ?
    ---------------------------------------
    u mean the realationship (bottom of attribute) (1:n, n:1)? no :/


    3.Which attribute's value in Entity A is filled in new_attribute2 ?
    ---------------------------------------
    new_name


    4.Which attribute's value in Entity A is needed for u to autofill in new_attribute3 ? use that attribute's name in the place  of"new_attribute1" in the above code.
    ---------------------------------------
    new_projectnumber (A) to new_projectnumber_read (B)

     

    ----------
    content more structured:
    ----------

    entity A (new_project) // attribute: new_projectnumber (nvarchar), new_name (nvarchar), new_projectid (primarykey)

    entity B (new_timesheet) // attribute: new_project1id (lookup), new_projectnumber_read (nvarchar)

     

     

    these code is onchange on new_project1id:


    var lookup1= crmForm.all.new_project1id;
    if( lookup1.DataValue != null )
    {
    var lookupColumns = lookup1.items[0].keyValues;
    crmForm.all.new_projectnumber_read.value=lookupColumns.new_projectnumber.value;
    }

  • 14 พฤศจิกายน 2551 3:57
     
     

     

    Hi,

    Ok. So the above code will works to fill the new_projectnumber_read attribute in B when u select new_project1id,right?

    Similarly why dont u fill the new_attribute3?

    We can autofill any number of fields using this method.But those fields should be present in the lookup view!

     

    var lookup1= crmForm.all.new_project1id;
    if( lookup1.DataValue != null )
    {
    var lookupColumns = lookup1.items[0].keyValues;
    crmForm.all.new_projectnumber_read.value=lookupColumns.new_projectnumber.value;

    crmForm.all.new_attribute2.value=lookupColumns.new_name.value;
    }

     

    Before that you jjst need to customize the lookup view of the entityA that u need to add the new_name and new_pprojectnumber in the lookup view.

    Settings>>customizations>>customizable entities>>Select entity A

    Select Forms and views>>lookupview and then add columns in the view.Save.TRY!

  • 14 พฤศจิกายน 2551 11:14
     
     

     

    there is a error displaying:

     

    Field: new_project1id
    Event: onchange
    Error: "new_name.value" is null or no object


    BUT it works ! Smile) field filling up correct after error message

    thx *thumbsup*

  • 14 พฤศจิกายน 2551 11:21
     
     

    Hi,

      try new_name.DataValue instead of using new_name.value

     

  • 15 พฤศจิกายน 2551 16:05
     
     
    doenst work, unfortunately
  • 17 พฤศจิกายน 2551 11:55
     
     คำตอบ

    Hi,

     The problem is some other. Bcoz its working finely here. Check the name of new_name field whether its correct or not.

    Such error message means it cant identity that field-new_name or its not initialised.

     

  • 20 พฤศจิกายน 2551 12:34
     
     

     

    now it works fine - thank you Smile