Resources for IT Professionals >
Dynamics Forums
>
CRM Development
>
How to get the order attribute values in Order Product's Form Load ?
How to get the order attribute values in Order Product's Form Load ?
- 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
- 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 - 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. - 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 - 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. - Hi,It is giving error because it is null.You could check for the null condition before fetching it's value.Regards,
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); } }
Nishant Rana
http://nishantrana.wordpress.com - 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

