Hi All,
I am trying to filter look up using fetchXML using Web Api .
i can do it in normal way. But i am trying implement the same using web api.
Please help anyone have any idea.
Thank you.
*This post is locked for comments
Hi All,
I am trying to filter look up using fetchXML using Web Api .
i can do it in normal way. But i am trying implement the same using web api.
Please help anyone have any idea.
Thank you.
*This post is locked for comments
Hi,
WebApi is not using "fetchXml" filtering syntax. Have a look at the examples here:
https://msdn.microsoft.com/en-us/library/gg334767.aspx#BKMK_FilterNavProperties
i have already done this in same way.
I am just curious is it possible to do using web api or not
Hi Nazir,
below is my code i have used for filtering product lookup..hope this help
function preFilterProductLookup() {
// this is for filtering product on form
Xrm.Page.getControl("productid").addPreSearch(function () {
var address = Xrm.Page.getAttribute("new_residenceaddress").getValue()[0].id;
var contact = Xrm.Page.getAttribute("responsiblecontactid").getValue()[0].id;
//get all the related product from salesorder
var fetchproduct ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
"<entity name='salesorder'>"+
" <attribute name='new_productsg1' />"+
"<filter type='and'>"+
" <condition attribute='new_residenceaddress' operator='eq' value= '" + address +"'/>"+
" <condition attribute='new_primarycontact' operator='eq' value= '" + contact +"'/>"+
"</filter>"+
"</entity>"+
"</fetch>";
var fetchproductdetail = XrmServiceToolkit.Soap.Fetch(fetchproduct);
var fetchXml;
if (fetchproductdetail.length > 0) {
var fetchXml = "<filter type='and'><condition attribute='productid' operator='in'>";
for(var i=0;i<fetchproductdetail.length; i++)
{
if(fetchproductdetail[i].attributes["new_productsg1"] != undefined)
{
fetchXml += "<value>" + fetchproductdetail[i].attributes["new_productsg1"].id +" </value>";
}
}
fetchXml += "</condition></filter>";
}
Xrm.Page.getControl("productid").addCustomFilter(fetchXml);
});
Thanks,
Shhabaaz
Hi Nazir,
Please try with the sample in the link.
No error.
simply not filtering the records in look up.
Hi Nazir,
Seems your fetchxml have some issue. What error your are getting ?
Try to make simple fetchxml first to test.
Hi Nazir,
You can get help from here-
community.dynamics.com/.../use-fetchxml-to-retrieve-data-from-ms-crm-2016-using-web-api
arvindcsit.blog/.../retrieve-data-using-web-api-and-fetchxml
Hope this helps.
function FilteringLookUpField()
{
debugger;
var LoggedInUserID=Xrm.Page.context.getUserId();
var fecthXML = "<filter type='and'><condition attribute='ownerid' operator='eq' value='"+LoggedInUserID+"' /></filter>";
var encodedFetchXml = encodeURI(fecthXML);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?fetchXml="+encodedFetchXml, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
var recordCount = results["@odata.count"];
alert(recordCount);
//if(result.value.length==0)
//{
// alert("There is no Account asscoiated to this owner");
//}
//else
//{
// for(var i=0;i<result.value.length;i++)
// {
// accountId=res
// }
//}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
This is my code. and it is not working :(
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156