Resources for IT Professionals > Dynamics Forums > CRM Development > How to get the order attribute values in Order Product's Form Load ?
Ask a questionAsk a question
 

QuestionHow to get the order attribute values in Order Product's Form Load ?

  • Tuesday, November 03, 2009 8:35 AMnagcrm Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Dear All,

    I am filtering products in the "order product" entity based on the Sales Order's Order Type. To get the value of Order Type Field value in Order Product I am using the following code.

    Parent Form: Order
    Child: Order Product

    Order Product Form Load:
    var oParentCrmForm = window.opener.document.all.crmForm;
    alert(oParentCrmForm.all.new_ordertype.DataValue);

    This is working perfectly when I am created new order product in the Order. But once I save and close and re-open the order product I am getting error like below..

    Field: window
    Event : OnLoad
    Error: all is null or not an object

    Kindly let me know how to get the order_type field value for existing after opening the order product.

    BR,
    NAG

All Replies

  • Tuesday, November 03, 2009 8:39 AMAndriy a33ik Butenko Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, Nag.

    The best way to get this data is to use WebServices to retrieve data.

    First step is to retrieve identifier of parent order like:
    var orderid = crmForm.all.<order lookup field>.DataValue[0].id;

    Second - retrieve parent order fields using Webservices. Check this url for reference.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
  • Tuesday, November 03, 2009 9:28 AMnagcrm Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Andriy,

    Thanks for the reply. As you said in the first step I tried. I am getting orderid since the orderlookup field is in the Order Product entity also. I want to retrieve another field called new_ordertype in the order entity. How to retrieve through Javascript. ?

    See for example. I have Order(Parent Entity), Order Product( which is 'Existing product' in the Order assumed as Child Entity)

    I wrote in the Order Product Form Load the following lines:

    var oParentCrmForm = window.opener.document.all.crmForm;
    var ordtype = oParentCrmForm.all.new_ordertype.DataValue;
    alert(ordtype[0].name);

    The above code is working fine and also showing  the alert.

    After you re-open the same order product line item i am getting java script error message like below..

    Field: window
    Event : OnLoad
    Error: all is null or not an object

    I want this value even if i open the existing order product.

    Please let me know..

    Thanks in Advance,

    NAG.
  • Tuesday, November 03, 2009 11:49 AMNishant Rana-MCAD-MCTS-MCBMSS-MCBMSP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    For an existing Order Product record you could use the following.

    window.opener.parent.document.getElementById('fieldname').value;
    

    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
  • Wednesday, November 04, 2009 10:56 AMnagcrm Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Pleae help me in the following code. I wrote same code in the Order form itself.  Same code I applied but it's giving error if the lookup value is empty. If the value was there it shows alerts. Same code in SDK.

    var lookupItem = new Array;


    lookupItem = crmForm.all.new_customerid.DataValue;

    if (lookupItem[0] != null)
    {
       // The text value of the lookup.
       alert(lookupItem[0].name);

       // The GUID of the lookup.
       alert(lookupItem[0].id);

       // The entity type name.
       alert(lookupItem[0].typename);

    }

    The error is: '0' is null or not an object.

    BR,
    NAG.
  • Wednesday, November 04, 2009 11:18 AMNishant Rana-MCAD-MCTS-MCBMSS-MCBMSP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    It is giving error because it is null.

    You could check for the null condition before fetching it's value.

    if(crmForm.all.pricelevelid.DataValue!=null)
    {
    
    var lookupItem = new Array;
    
    lookupItem = crmForm.all.pricelevelid.DataValue;
    
    if (lookupItem[0] != null)
    {
       // The text value of the lookup.
       alert(lookupItem[0].name);
    
       // The GUID of the lookup.
       alert(lookupItem[0].id);
    
       // The entity type name.
       alert(lookupItem[0].typename);
    
    }
    
    }
    
    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
  • Wednesday, November 04, 2009 5:37 PMDavidBerry Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    FYI:  There is a hidden attribute on Order Product forms, crmForm.salesorderid.value which is the GUID of the Order which parents the Order Product.  Using that, in conjunction with the code in my blog http://crmentropy.blogspot.com/2009/11/easy-to-use-javascript-retrieve-and.html should make it very easy to retrieve information from the Order.
    Dave Berry