Asked by:
Load subgrid based on another Look up error

Question
-
Hi all,
i am trying to Load Subgrid Value based on another Lookup in CRM2013. But I can't able to Achieve that. Steps i have done below
Function onload()
{
subgridprojectidload()
}
function subgridprojectidload() {
var grid = document.getElementById('ProjectID');
if (grid == null) {
setTimeout('subgridprojectidload()', 2000);
}
else {
var lookupfield = new Array;
lookupfield = Xrm.Page.getAttribute("new_financeidid").getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].name;
}
else {
return;
}
var fetchXml = "<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>";
fetchXml += "<entity name='new_projectid'>";
fetchXml += "<attribute name='new_projectidid'/>";
fetchXml += "<attribute name='new_name'/>";
fetchXml += "<attribute name='createdon'/>";
fetchXml += "<order descending='false' attribute='new_name'/>";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='new_name' value='%" + lookupid + "%' operator='like'/>";
fetchXml += "</filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";
grid.control.SetParameter("fetchXml", fetchXml);
grid.control.refresh();
}
}Eg: In lookup iam having a value as 22254 means in Subgrid i need to load the values which contain (22254)
( ie )22254_2222_Adfkasdkfklnmasdf
Tuesday, November 26, 2013 1:19 PM
All replies
-
Hi all,
i am trying to Load Subgrid Value based on another Lookup in CRM2013. But I can't able to Achieve that. Steps i have done below
Function onload()
{
subgridprojectidload()
}
function subgridprojectidload() {
var grid = document.getElementById('ProjectID');
if (grid == null) {
setTimeout('subgridprojectidload()', 2000);
}
else {
var lookupfield = new Array;
lookupfield = Xrm.Page.getAttribute("new_financeidid").getValue();
if (lookupfield != null) {
var lookupid = lookupfield[0].name;
}
else {
return;
}
var fetchXml = "<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>";
fetchXml += "<entity name='new_projectid'>";
fetchXml += "<attribute name='new_projectidid'/>";
fetchXml += "<attribute name='new_name'/>";
fetchXml += "<attribute name='createdon'/>";
fetchXml += "<order descending='false' attribute='new_name'/>";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='new_name' value='%" + lookupid + "%' operator='like'/>";
fetchXml += "</filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";
grid.control.SetParameter("fetchXml", fetchXml);
grid.control.refresh();
}
}Eg: In lookup iam having a value as 22254 means in Subgrid i need to load the values which contain (22254)
( ie )22254_2222_Adfkasdkfklnmasdf
What's the error you are getting? Subgrid is empty or JS sends some error. Please provide detail. And also make sure that your subgrid Data Source settings, use All Record Types. In this example, I am using Open Activities as the default view but you can use which ever suites your needs.
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!Wednesday, November 27, 2013 5:29 AM -
Hi Mubasher,
Thanks for your reply, but if i select 22254 in lookup means in subgrid i need to manually select the values based on the Lookup selection (22254)
Wednesday, November 27, 2013 5:48 AM -
Hi Jerry
No you are wrong if i understand your requirement properly than this is the process that you want.
1: Onload of form get the lookup value from a new_financeidid
2: Update the subgrid with the condition attribute='new_name' value='%" + lookupid + "%' operator='like'/
The above code will automatically update the Grid according to your condition. and if you want to run the JS on change of the new_financeidid then you can add the same function onchange of new_financeidid.
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!Wednesday, November 27, 2013 6:40 AM -
HI Mubasher,
User need to select the Values. If i done as per your suggestion means it will display all the values and refresh in sub grid.
Thursday, December 19, 2013 7:13 AM -
HI all,
i need to load the subgrid values based on a Lookup field.
If i select Account entity "ONLINE" means in Subgrid if i Click PLUS button i need to show only the Records which contains ONLINE (N:N Relationship)
Is it possible to achieve anyway. If so please share step by step code below.
Thanks in Advance.
- Edited by rampprakash Thursday, December 19, 2013 2:14 PM
- Merged by Andrii ButenkoMVP, Moderator Thursday, December 19, 2013 4:43 PM The same thread
Thursday, December 19, 2013 2:14 PM -
Hi All,
I need to Filter Add existing Lookup in CRM 2013.
(Eg) I have a Lookup field Called Account, and i selected a Value as "SUBCHECK", and am having a Subgrid in the Same form for Horizontal. If user Clicks +(PLUS) Button in subgrid it should display only the values which contain "SUBGRID"(Based on Account It should Load). Is it Possible to achieve.
- Merged by Andrii ButenkoMVP, Moderator Friday, December 20, 2013 10:28 AM The same thread
Friday, December 20, 2013 4:40 AM -
yes you can do it on change of the lookup you need write javascript to filter the subgrid
http://balarajann.blogspot.in/2013/01/filtering-records-in-sub-grid-in.html
check the above links ...........
ms crm
Friday, December 20, 2013 6:07 AM -
Hi,
This code will work for you.
function funName_onload() { var grid = document.getElementById('LeadActivity'); if (grid ==null) { setTimeout('funName_onload()', 2000); } else { var lookupfield = new Array; lookupfield = Xrm.Page.getAttribute("originatingleadid").getValue(); if (lookupfield != null) { var lookupid = lookupfield[0].id; } else { return; } var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"; fetchXml += "<entity name='activitypointer'>"; fetchXml += "<attribute name='regardingobjectid' />"; fetchXml += "<filter type='and'>"; fetchXml += "<condition attribute='regardingobjectid' operator='eq' value='" + lookupid + "' />"; fetchXml += "</filter>"; fetchXml += "</entity>"; fetchXml += "</fetch>"; grid.control.SetParameter("fetchXml", fetchXml); grid.control.Refresh(); } }
Thanks, MS CRM Developer, Ranjan
Friday, December 20, 2013 6:46 AM -
Hi Reddy & Rajan,
Based on your Code we can show all the data based on Account Selection. I need as
(Eg) if i select account as "SUBGRID" means i need to select values which contain Subgrid123 only. if subgrid values contains 100 subgrid123 means i need to select only one or two by clicking add existing button
(I need to filter the "Add Existing" button on Subgrid based on Account Lookup)
- Edited by rampprakash Friday, December 20, 2013 9:35 AM
Friday, December 20, 2013 9:18 AM