Monday, September 15, 2008

Display Fetch in Iframe


The fetch viewer is a very handy utility class that accepts advance find parameters and “injects” the result into any IFRAME.

The nice thing about it is that it does not require any server side deployment (no code behind). The code creates a dynamic FORM fills the required advanced find parameters and submits the request to the fetchdata.aspx which is the advanced find result page. The code also takes care of iframe padding and presents a loading gif until the page is rendered.


In order for this to work you need to specify all the required parameters such as FetchXml , LayoutXml , EntityName and the DefaultQueryId for the requested entity. The idea is to create a complete request using the advanced find window, concatenate fetchxml dynamic values, assign the predefined masterpiece to the FetchViewer class and use the Refresh method to finish the job.

You can get the fetch parameters by pasting the following code in the advanced find window addressbar.



javascript:void( new function(){ prompt("Fetch Parameters:",getFetchParams());function getFetchParams(){ return "FetchXml:\n" + advFind.FetchXml + "\n\n" + "LayoutXml:\n" + advFind.LayoutXml + "\n\n" + "EntityName:\n" + advFind.EntityName + "\n\n" + "DefaultAdvancedFindViewId:\n" + advFind.DefaultAdvancedFindViewId } } )



Please notice, I’ve revised the code to support iframe positioning on any tab.
Iframes that aren’t located on default tab should be handled a bit differently since the iframe url is handled by crm (even if the initial url is about:blank).

When the form loads call the RegisterOnTab with the iframe position tabIndex. If the iframe is located on the default tab the refresh method will be called immediately otherwise crm will trigger the onreadystatechange event which will eventually call the Refresh method. The RegisterOnTab should be called only once per iframe and only from the onload event. Afterwards, if you need to revise the iframe Display call the iframe FetchViewer.Refresh method directly.



I upgraded the FetchViewer class and now it supports parent context (mapping) and grid refresh. You can read more about it here


function OnCrmPageLoad()
{
window.fetchAccounts = new FetchViewer("IFRAME_test1");
fetchAccounts.FetchXml = getFetchXml();
fetchAccounts.LayoutXml = getLayoutXml();
fetchAccounts.Entity = "account";
fetchAccounts.QueryId = "{00000000-0000-0000-00AA-000010001001}";
fetchAccounts.RegisterOnTab(0); //IFRAME ON THE DEFAULT TAB

window.fetchAccounts1 = new FetchViewer("IFRAME_test");
fetchAccounts1.FetchXml = getFetchXml();
fetchAccounts1.LayoutXml = getLayoutXml();
fetchAccounts1.Entity = "account";
fetchAccounts1.QueryId = "{00000000-0000-0000-00AA-000010001001}";
fetchAccounts1.RegisterOnTab(2); //IFRAME ON THE THIRD TAB (index eq 2)

crmForm.all.gi_name.attachEvent( "onchange" , WhenThisFieldChangesAndCallRefresh );
}

function WhenThisFieldChangesAndCallRefresh()
{
//Change the fetchAccounts.FetchXml ( for example ) and Refresh
fetchAccounts.Refresh();
}

function getFetchXml(){
return '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"><entity name="account"><attribute name="name"/><attribute name="address1_city"/><attribute name="primarycontactid"/><attribute name="telephone1"/><attribute name="accountid"/><order attribute="name" descending="false"/><filter type="and"><condition attribute="ownerid" operator="eq-userid"/><condition attribute="statecode" operator="eq" value="0"/></filter><link-entity name="contact" from="contactid" to="primarycontactid" visible="false" link-type="outer" alias="accountprimarycontactidcontactcontactid"><attribute name="emailaddress1"/></link-entity></entity></fetch>';
}

function getLayoutXml(){
return '<grid name="resultset" object="1" jump="name" select="1" icon="1" preview="1"><row name="result" id="accountid"><cell name="name" width="300" /><cell name="telephone1" width="100" /><cell name="address1_city" width="100" /><cell name="primarycontactid" width="150" /><cell name="accountprimarycontactidcontactcontactid.emailaddress1" width="150" disableSorting="1" /></row></grid>';
}

function FetchViewer( iframeId )
{
var Instance = this;
var vDynamicForm;
var m_iframeTab;
var m_iframeDoc;

Instance.Entity = "";
Instance.Iframe = null;
Instance.FetchXml = "";
Instance.QueryId = "";
Instance.LayoutXml = "";

Instance.RegisterOnTab = function( tabIndex )
{
Instance.Iframe = document.getElementById( iframeId );

if( !Instance.Iframe )
return alert( "Iframe " + iframeId + " is undefined" );

m_iframeDoc = getIframeDocument();
var loadingGifHTML = "<table height='100%' width='100%' style='cursor:wait'>";
loadingGifHTML += "<tr>";
loadingGifHTML += "<td valign='middle' align='center'>";
loadingGifHTML += "<img alt='' src='/_imgs/AdvFind/progress.gif'/>";
loadingGifHTML += "<div/><b>Loading View...</b>";
loadingGifHTML += "</td></tr></table>";
m_iframeDoc.body.innerHTML = loadingGifHTML;

if( parseInt( "0" + tabIndex ) == 0 ) Instance.Refresh();
else Instance.Iframe.attachEvent( "onreadystatechange" , RefreshOnReadyStateChange );
}

function RefreshOnReadyStateChange()
{
if( Instance.Iframe.readyState != 'complete' )
return;

Instance.Refresh();
}

Instance.Refresh = function()
{
if( !Instance.Iframe )
return alert( "Iframe " + iframeId + " is undefined" );

m_iframeDoc = getIframeDocument();

Instance.Iframe.detachEvent( "onreadystatechange" , RefreshOnReadyStateChange );

var create = m_iframeDoc.createElement;
var append1 = m_iframeDoc.appendChild;
vDynamicForm = create("<FORM name='vDynamicForm' method='post'>");

var append2 = vDynamicForm.appendChild;
append2(create("<INPUT type='hidden' name='FetchXml'>"));
append2(create("<INPUT type='hidden' name='LayoutXml'>"));
append2(create("<INPUT type='hidden' name='EntityName'>"));
append2(create("<INPUT type='hidden' name='DefaultAdvFindViewId'>"));
append2(create("<INPUT type='hidden' name='ViewType'>"));
append1( vDynamicForm );

vDynamicForm.action = prependOrgName("/AdvancedFind/fetchData.aspx");
vDynamicForm.FetchXml.value = Instance.FetchXml;
vDynamicForm.LayoutXml.value = Instance.LayoutXml;
vDynamicForm.EntityName.value = Instance.Entity;
vDynamicForm.DefaultAdvFindViewId.value = Instance.QueryId;
vDynamicForm.ViewType.value = 1039;
vDynamicForm.submit();

Instance.Iframe.attachEvent( "onreadystatechange" , OnViewReady );
}

function OnViewReady()
{
if( Instance.Iframe.readyState != 'complete' ) return;

Instance.Iframe.style.border = 0;
Instance.Iframe.detachEvent( "onreadystatechange" , OnViewReady );
m_iframeDoc = getIframeDocument();
m_iframeDoc.body.scroll = "no";
m_iframeDoc.body.style.padding = "0px";
}

function getIframeDocument(){
return Instance.Iframe.contentWindow.document;
}

}

OnCrmPageLoad();

70 comments:

HYap said...

Adi,

Thank you for this really useful blog.

I got this to work for accounts, but I want to implement it for other entities.

1) Is there a way to find out what the Default Query Id is for the different entities?
2) Is there a way to get the LayoutXML?
3) What is the ViewType property?

Thank you,
Holson

Adi Katz said...

Hi Holson,

I modified the post and add a script that extracts the required fetch parameters form the advanced find window.

Good luck

Anonymous said...

Hi,

Do I need to set the I-Frame URL to anything when initially customizng the form?? I have it currently set to about:blank

My results do not appear to refresh and display in the I-Frame even though I have corectly set the Entity name, Query Id, etc..

Is there something missing for settign the I-Frame source??


I have managed to however get this working in a custom aspx page but would like to get this working with JavaScript as deploying to a hosted environment with no admin access to deploy custom aspx.

Thanks

Karen

Adi Katz said...

Hi Karen,

You should use about:blank. The iframe url is filled with ms fetchdata.aspx.

First thing that comes into mind is line 35; the blog doesn’t like <BRs> so this will break your code (string).

Another thing is, if your trying to call the Refresh more then once, from another field onchange event for example, then you need to alter the first line and instead of

var fetchViewer = ...

you should “register” the variable at the window level like so

window.fetchViewer = ...

I’ve changed the code on the blog to reflect this.

Good luck

Anonymous said...

Hi Adi,

nice work! But I'm still struggeling with the target of the iFrame: the result is opened in a new browser.

Which settings do you use for the iFrame? Typecodes/Scripting?

Adi Katz said...

Hi Gregor,

The IFRAME initial URL should be set to about:blank inside the IFRAME customization dialog (not script).

I don’t use TARGET since the Form is built inside the IFRAME using the IFRAME document.createElement and document.appendChild functions.

Line 54 calls the getIframeDocument() function which returns the IFRAME document object (Instance.Iframe.contentWindow.document).

You might have forgotten to uncheck the “restrict cross-frame scripting” checkbox or the code has an error that you’re missing.

Anonymous said...

Hi Adi,

wow - this is a fast reply!
I tried all possible settings of the checkbox.

If I uncheck the result of the advanced find opens in a new browser.
If I check it I do get the "Navigation cancled" Message in the iFrame.

My Problem: as soon as I navigate to the tab with the iFrame a Error occurs in the page:

Debuginformation for Microsoft:

...
Function getIframeDocument()
FunctionOnIframeStateChange()
...

any idea?

thx
Gregor

Adi Katz said...

Hi Gregor,

I've revised the code, please check it now and confirm that it works.

Thanks,
Adi

Anonymous said...

Hi Adi.
Thank you for this blog. I tryed use this code but the result opened not in frame but in new IE window. (after submit opened new window with search's result).
Why?

Dmitriy

Adi Katz said...

I’ve tested this on IE6 and IE7 both in trusted sites and Intranet zone and I can’t reproduce what you have described.

Check that the IFRAME setting in customization are correct i.e. url equals about:blank and uncheck disable cross-iframe scripting checkbox.

What are your settings? Post them here so I’ll be able to compare them briefly.

Anonymous said...

hey Adi

I have this set up well, however what do i need to do if i would like to put the iframe on another tab?

thanks

Adi Katz said...

Hi Jonathan,

Have a look at line 15, the code registers the IFRAME_Test on the third Tab (Tab Index = 2)
fetchAccounts1.RegisterOnTab(2);

Adi

Anonymous said...

Hi Adi

just out of interest, is there a way we can make the notes that appear here read-only, so you wouldnt be able to create more in this window?

great site

Adi Katz said...

Hi Jonathan,

The post above does not contain or refer to notes.
If you’re referring to my post about “playing with notes” then the notes grid is read-only in that sense since you the new button does not show. There is a way of course you can hide the entire grid toolbar to disable creating new entities. I’m not sure I fully understood your comment so feel free to elaborate on that again.

Adi

Anonymous said...

Excellent Tool!!! Thank you.

Is there a way to use it from a custom web application?


J

Adi Katz said...

Yes you can.

Notice that the urls in the code use relative paths, so you need to change that if you don’t intend to create a virtual directory under the ISV folder.

You may also encounter a permission denied which can be resolved by lowering the security settings of your web app and putting it in the trusted sites.

Adi

Anonymous said...

Thanks again. I have another quick question, if I may? Is there a way to get( via event) the selected index changed of the data returned? Meaning if I select a row, is it feasible to retreive some of the row data?

J

Adi Katz said...

Hi J,

You can either drill into the crmgrid and get what you can see or get the selected row Guid (entity id) and do an Ajax request to retrieve any of the entity attributes (fields). The post decorating crmgrid columns has a good example of how to drill into the crmgrid. You can also use the following post the retrieve data via Ajax Ajax using fetch message

Good Luck
Adi

Todd Langdon said...

STUPID question: Where do we place your code? does it go in the OnLoad event of the entity form that contains the IFrame?

Adi Katz said...

Hi Todd,

Yes, this is exactly what you should do!

Note:
If you’re testing this in a development environment I suggest putting the code in an external js file until you its ready for production. Then you can paste it back inside the entity onload event box.

Anonymous said...

Hi Adi,
WOW that's cool. It is working perfect.
One small thing: When I have an extended query with linked entities and I set an order inside the linked entity the result in the IFrame/fetchXML ignores the sorting and displays the order in which the data was entered in the entity :-(

When I sort on a column that is completely empty then the sorting defined in the query is used :-o

Is there a way to call the 'default' sorting on purpose for the IFrame?

Example:
I would have liked to give an example but in this post it is not allowed to use other tags than a, i and b.

Thanks,
Thomas

Anonymous said...

Great! Thank you!

frederic demeilliez said...

This post is really great!!!! That was the kind of code I needed!

I had to show all the activities of that particular "account"! So I've created an "advanced view" for all activities, and I added as "Party" a dummy account. In javascript you just change the "GUID" with "crmForm.ObjectId" and it works like heaven!!

Really thx for your piece of code!

Frederic :)

Anonymous said...

Hi Adi. Please, help me to understand it:

I want to get fetch view in IFrame without icon and preview, and without using any JScript code.

LayoutXml has attributes:
grid name="resultset" object="1" jump="name" select="1" icon="1" preview="1"

icon, preview - how can I off it?
set value 0, "off", false,
delete attributes
it all does not work :(
how it to do?

Thanks,
Dmitry

Adi Katz said...

I’ve been there already, tried every configuration possible and came to a conclusion that this part
of the layoutxml is not configurable but simply a representation of what is.

Adi

Anonymous said...

The grid works pretty well, but I have a couple of things:

1) Using the SERVER_URL variable and instead of ORG_UNIQUE_NAME would make this work in IFD mode and CRM Online deployments also.

2) I imagine most use of the grid would be for the purposes of displaying related entity records instead of relying on the left-side navigation menu (I'm doing this to help create a cleaner interface). The problem, though, is that when you create a new record, the relationship does not carry over because it doesn't look like the grid passes the parameters to the entity's create form. I know that's mainly because the Advanced Find isn't designed to operate in that fashion, but it's be nice to try and come up with a work-around.

Cheers!
Will

gprof said...
This comment has been removed by the author.
Anonymous said...

Hi Adi,

I've pasted the entire code in the onload but I get an Access is denied error.

Do I need to change some security setting for this to work?

Thanks Geron

Adi Katz said...

Try putting CRM in the trusted sites. Don’t forget to remove the iframe the cross scripting restriction from the customization.

Adi

Dave Berry said...

PingBack from:
http://6ix4our.blogspot.com/2009/03/microsoft-crm-embedding-advanced-find.html

Anonymous said...

Hi Adi,

I managed to get your code to work but only on the default tab (index=0). If I place the code on any other tab I get an "Access is denied" error. CRM is indeed in my trusted sites and cross scripting is off.

Can you clarify a bit more on what I need to do to put this on a tab other tha the default?

Also, would it be possible to display this directly from the NavPane (as opposed to on a tab)?

Hope you can help me.

Thanks again,
Geron

Adi Katz said...

The following line of code registers the IFRAME on the third tab:

fetchAccounts.RegisterOnTab(2);

Asafus said...

Hi Adi,

You're true CRM'ing fighter - no doubt about that.
I wish to post a small question to you (pardon - dont know where...)

As Guru developer on multilingual CRMs (Israel), you probably encountered the annoying constant "Language-Switching" between System-Lang (require for customizations) to UI lang (let's say – Hebrew).

do you have a creative idea how to change UI language using ISV menus with Javascript?

I've tried to be inspired by MS implementation of “Personal Options” dialog, looked @ sdk and googled everywhere.

Any salvation ?

Asaf, ISRAEL ☺

Adi Katz said...

Hi Asaf,

You can use the UpdateUserSettingsRequest to change the user uilanguageid column and refresh the CRM window to get the desired results.

Unknown said...

Adi,

I see the function you provided to get the FetchXML and have successfully exposed the address bar in my Advanced Find window, however the address bar is "locked" - I can't change the URL in the address bar.

Is there a browser setting I'm missing to allow me to change the address bar to use the javascript to get the FetchXML?

Thanks,
-Chuck

Adi Katz said...

Open the AF window --> Do a Ctrl + N and open a new AF window --> Create your query --> paste the above code in the addressbar --> click enter.

Adi

Asafus said...

I suppose using UpdateUserSettingsRequest unsupported (OK wih me).

where can I see the function implementation/declaration (parameters, return value..)?

In which JS file is it in?

thanks so much for the quick response!

Asaf.

Adi Katz said...

The UpdateUserSettingsSystemUserRequest is a genuine SDK request object which you can operate (retrieve,update) from the client using ajax.

Search the crm 4.0 sdk for complete information.

Unknown said...

I initially had the same problem as the anonymous poster a few comments back; placing my custom Iframe on a tab other than the first tab resulted in an "Access denied" error.

Apparently, the security settings in use in my environment have "about:blank" in a different domain than the CRM server (or perhaps this is the expected state when client and CRM are not running on the same box).

To work around this condition, I created a blank HTML page and placed it in the root of CRMWeb on the CRM server. I then pointed my Iframe to that location initially - problem (inelegantly) solved.

While I will have to manage this link as I deploy it from development into production, it's better than not being able to use Adi's tip at all.

Adi Katz said...

If you put about:blank in the trusted sites doesn’t that solve your problem?

Unknown said...

Adi,

I would have thought it would have, but I just added "about:blank" to my trusted sites, crushed IE and relaunched and my formerly-working implementation of advanced-find-in-a-can is now showing a "Navigation to the webpage was canceled" error with the error data indicating an "Access Denied" error.

Either way, as we're attempting a "zero-client-footprint" installation of CRM at client site, I'm attempting to come up with a solution that will not require us to update every user's IE preferences (or deploy an automated script to do same).

Thanks for your continued attention to our trials and tribulations!

Anonymous said...

Hi Adi,

Excellent post! Is it possible to use this within navigation pane of an entity instead of an IFrame?

Thanks.

Raj

Adi Katz said...

This solution is strictly built for IFRAMES. You can implement the same solution in a simple HTML page which contains an IFRAME and this script. Put the HTML page in the isv folder and build a new navigation link through isv.config.

Bryce said...

Replace line 96 with the following so that it works on IFD servers also.

vDynamicForm.action = prependOrgName("/AdvancedFind/fetchData.aspx");

Owen Geraghty said...

I'm using this custom ASPX page to display a contact, with contract start and end date on the account entity. The fetch XML works fine - it gets the contact name and id, and the contract start and end dates. The problem is in the layout XML. Because my fetch statement gets attributes from multiple entities, only the details from the main entity are formatted correctly. As such, the dates from the contract show up as they would in the database, and the labels for these appear as ab.sol_startdate and ab.sol_enddate. Is there a way to change the labels on the view in the layoutXML, and is there a way to format the data as it comes in.

Code included below:
I replaced all < with (, and all > with ), since otherwise this page thinks I'm using HTML tags.

FetchXML(fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true')(entity name='contact')(attribute name='fullname'/)(attribute name='contactid'/)(order attribute='fullname' descending='false'/)(link-entity name='sol_contract_contact' from='sol_performerid' to='contactid' alias='aa')(link-entity name='sol_contract' from='sol_contractid' to='sol_contractid' alias='ab')(attribute name='sol_startdate' alias='Start Date'/)(attribute name='sol_enddate' alias='End Date'/)(filter type='and')(filter type='or')(condition attribute='sol_dentalproviderid' operator='eq' uiname='16a Dental' uitype='account' value='" + FilterID + "'/)(condition attribute='sol_accountcontractid' operator='eq' uiname='16a Dental' uitype='account' value='" + FilterID + "'/)(/filter)(/filter)(/link-entity)(/link-entity)(/entity)(/fetch)

LayoutXML:(grid name='resultset' object='2' jump='lastname' select='1' icon='1' preview='1')(row name='result' id='contactid')(cell name='fullname' width='240' /)(cell name='sol_performernumber' width='100' /)(cell name='ab.sol_startdate' width='180'/)(cell name='ab.sol_enddate' width='180'/)(/row)(/grid)

Adi Katz said...

Did you build the LayoutXml using advanced find? If the advanced find shows the related columns correctly there is no reason why the iframe viewer won’t.

The display of column names is an automated process. I don’t think there is a comfortable way to intervene

Owen Geraghty said...

I originally built the layoutXML from the advanced find, but advanced find only allows a query to retrieve attributes from a single entity, so I've altered my layout and fetch statements to get attributes from multiple entities.

I have solved one of my problems(actually worked around it). When the date was completely unformated, I made the main entity the contract where the date is being picked up, so the date is correctly formatted. Now the only issue which is not as serious is that the fullname field is titled Contact.Fullname, and performerid is Contact.sol_performernumber.

I've included my workaround fetch and layout statements below, again with ( instead of < and ) instead of >.

FetchXml = @"(fetch mapping='logical')(entity name='sol_contract')(attribute name='sol_enddate' alias='End Date'/)(attribute name='sol_startdate' alias='Start Date'/)(filter type='or')(condition attribute='sol_accountcontractid' operator='eq' value='" + FilterID + "'/)(condition attribute='sol_dentalproviderid' operator='eq' value='" + FilterID + "'/)(/filter)(link-entity name='sol_contract_contact' from='sol_contractid' to='sol_contractid' link-type='inner')(link-entity name='contact' from='contactid' to='sol_performerid' link-type='inner' alias='Contact')(attribute name='fullname'/)(attribute name='sol_performernumber'/)(/link-entity)(/link-entity)(/entity)(/fetch)";

LayoutXml = @"(grid name='resultset' object='10001' jump='sol_contractnumber' select='1' icon='1' preview='1')(row name='result' id='sol_contractid')(cell name='Contact.fullname' width='250'/)(cell name='Contact.sol_performernumber' width='180'/)(cell name='sol_startdate' width='100'/)(cell name='sol_enddate' width='100'/)(/row)(/grid)";

Anonymous said...

Hi Adi,

I have successfully used your code and applied it to the default tab. However, when I try to place it on a different tab, I am unable to have the iFrame display.
When I open the record, and switch to the tab, I am able to see the correct iFrame view for a split second, and then I receive the "Navigation to webpage was canceled" screen.
I believe there is something that is triggering the getIframeDocument() function when I switch tabs.
Have you encountered this problem before? Thank you in advance for any assistance you can provide.

Adi Katz said...

the RegisterOnTab function should address this issue. just pass a tab index to the RegisterOnTab e.g. RegisterOnTab(2) (third tab)and it should trigger the iframe load after the tab is selected.

Söderåsen said...

Hi Adi, I have a beginner's question how to put a button on top of AdvanceFind page like your solution?

Ian Luxton said...

Big thanks Adi...
This helped with a customer issue where a N:N with a custom entity in the middle broke bulk editing access. I just pulled the Account related entities back to an IFrame by passing the GUID to the advanced find. Nice. Thanks again.

Anonymous said...

Hello Adi,
I have never worked with XML nor do I understand the syntax. But do know that this solution will work for me.
On the 5th TAB of the Account, I want to place the Iframe which will use a AF queries a custom entity that is already created. I have gotten to a point where I am able to determine the 4 paramaters(fetchXml,Layout,entity name and Id)

Question I have is where the FetchViewer is defined :
window.fetchAccounts = new FetchViewer("IFRAME_test1");

window.fetchAccounts1 = new FetchViewer("IFRAME_test");

Do I need to define both of these ?

Sorry guys, just not up there as you guys seem to be. But I will, if you can help.

Thanks

-Gustho

Adi Katz said...

You need to define a window.[some variable] for every iframe that instantiates the fetchviewer class.
The use of window [dot] variable exposes the fetchviewer instance to the window scope so you can manipulate it from an toolbar button or a field onchange handler.

Anonymous said...

Now I get a error message, like so
Line :440
Char:7
Error:Access is denied
Code:0
url:http://crm/sfa/accts/edit.aspx?id={FD52......})

prior to this I was getting error (null or object not found) for crmForm.all.gi_name.attachevent.
So commented it out.
BTW, I am using CRM 3.0,I dont know if there is a compatibility issue here with 3.0.
-G

Anonymous said...

Has anyone been able to make the sort order to work properly? I tried the comment by Thomas (set sort to blank column) to no avail. No matter what I do I just get information sorted by what appears to be the order in which the data was entered.

Irinel BIRSAN said...

What the gi_name reffers to?

Adi Katz said...

gi_name is a custom field used in this sample. The field is used to show how to reconstruct a dynamic fetchxml and refresh the iframe with new results.
If you don’t use dynamic fetch then you should remove line 17, Otherwise replace the gi_name with your own field , reconstruct the fetchxml and call the fetchviewer.Refresh method.

Edwin Valenti Clari said...

Good stuff! But I am having troubles getting the ordering right. We are using a rather simple query on the ActivityPointer entity, no linked entities or some. We prefer to sort on standard date fields like 'actualend'.

We are applying the [order attribute]-node, but no such luck. It seems to order on some other field. I have seen other comments about the ordering-issue, but no solutions so far.

Adi - or anybody - who has a suggestion?

Edwin Valenti Clari said...

Solved the default-sorting issue as described in above comment. For everybody else to read;

The sorting is (of course ;o) not dependant on the query, but on the grid-component itself. Thanks to Dave Berrys' 'CRM Entropy' I found two Adv. Find form parameters that handle the default-sorting;
- SortCol ("Attribute Schemaname")
- SortDescend ("true" or "false")

Incorporate these params in
(1) The OnCrmPageLoad-function
(2) The Instance.attributes
(3) The append2-variable
(4) The vDynamicsForm.attributes

Works like a charm!
Great respect to Adi and Dave.

Irinel BIRSAN said...

Thanks for you answer

Still, how can i handle the iframe refresh when adding a new entity. After adding a new entity i need to hit the refresh icon to see it. Hoe can i make this automatically?

Adi Katz said...

The following post discusses this issue…

http://mscrm4ever.blogspot.com/2009/03/display-fetch-in-iframe-part-2.html

Anonymous said...

Did this work custom entity??

Anonymous said...

Is it possible to replace an associated view with this? I would like to use the existing navbar link and use a custom fetch as described above instead of the built in associated view... Any guidance is appreciated.

Unknown said...

Hi Adi, thank you for posting such informative blog.

I'm a little lost about the Windows.FetchAccounts and all of the FetchAccounts functions. I'm trying to do this with a custom entity actually. What Fetch function should I use here, and what Windows.(somefunction) should I declare?

Thanks!

-Elizabeth

Unknown said...

hi,

An excellent article, really adds value to a CRM system and its useability.
What are the restrictions with using FetchXML, with regards to the complexability of the advanced find?
Also is this customisation supported within CRM 2011?

Cheers for assistance.
ian

Anonymous said...

thanks ,
fetchXYZ.RegisterOnTab(1); // is not working
fetchXYZ.RegisterOnTab(0); // is working
---------
i am getting an error on page , when placing the iframe in other than the default Tab (0),
the error disappeared when using the default tab.
i am changing the code to register on the right Tab , but no lock .
any clue ?

Guru Prasad said...

Great piece of code..


Thanks.. I tried it in CRM 2011, with some changes got working..


Thanks for great article...

Naga Gotama said...

Hi all,
i want to ask you related advanced find in crm 2011.
can i create a pop up window (or own page) to display advanced find filter? for example, i want to create a feature in crm 2011 which user can define own filter and display/generate data depends on the conditions that he fill. after that, i want to add some button that do several task which using that data (or selected data from the grid result). can i? and how?

thanks.

Jose said...

Hello,

The code works but how does it reference a particular Account. If I open Account and navigate to the tab. I see all records but it display all records for every account instead of showing only records for that particular account. Any thoughts?

Jose

Clintolin said...

I am getting a cross site scripting error when pasting the javascript in the URL box. I see that you mention unchecking the "restrict cross-frame scripting" box, but cannot find it. How can I get around this?