Hi Alex,
You have errors in the fetchxml string...
You cannot have " in string concatenation, and then in the string it self...
When you use " for concatenation, inside the string you should use ' sign, or the other way around.
So this:
"<entity name="product">" +
"<attribute name="name" />" +
should be
"<entity name='product'>" +
"<attribute name='name' />" + ....
When writing JavaScript I'd suggest you do it in visual studio, or some other ide supports writing javascript, so you can see your typo errors better.
Try this below:
function SubLookupFilter(orderid, ordername) {
var _viewId = "{10CACCF3-AC63-46FE-920B-DFEF53BCDE33}";
var _entityName = "product";
var _viewDisplayName = "Products of Order : " + ordername;
var _fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' +
'<entity name="product">' +
'<attribute name="name" />' +
'<link-entity name="salesorderdetail" from="productid" to="productid" alias="ag">' +
'<link-entity name="salesorder" from="salesorderid" to="salesorderid" alias="ah">' +
'<filter type="and">' +
'<condition attribute="salesorderid" operator="eq" value="' + orderid + '"' + ' />' +
'</filter>' +
'</link-entity>' +
'</link-entity>' +
'</entity>' +
'</fetch>';
var _layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='OrderProducts'>" +
"<cell name='name' width='250' />" +
"</row>" +
"</grid>";
var lookupControl = Xrm.Page.getControl('new_service');
lookupControl.addCustomView(_viewId, _entityName, _viewDisplayName, _fetchXml, _layoutXml, true);
}
function Subscription_OnLoad() {
var attrs = Xrm.Page.data.entity.attributes;
if (attrs.get("new_subscriptionorderid").getValue() != null) {
var _orderid = attrs.get("new_subscriptionorderid").getValue()[0].id;
var _ordername = attrs.get("new_subscriptionorderid").getValue()[0].name;
SubLookupFilter(_orderid, _ordername);
}
}
Also try Xrm.Page.getControl function instead of Xrm.Page.ui.controls.get.
I have also change your query to use the orderid and not the ordername. If you use the ordername there might be many orders with the same name, so you should use the Guid orderid so it gets the unique order.
Let me know how it goes