Displaying Multiple List Blocks using the ASP COM API

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Displaying Multiple List Blocks using the ASP COM API

  • Comments 21
  • Likes

We have seen in other posts that it is perfectly possible to create ASP pages that contain multiple blocks. These have been search pages or entry pages that have drawn their blocks from either the same or different entities.


What we have not discussed so far is the display of multiple list blocks within the same page. Consider the idea of creating a page in the context of a company that brings together the cases and opportunities for that company.

The effect would be like the Quicklook screen only what we would like to be able to do rather than have only 4 rows displayed have the 10 or so rows that is set by our preferences and it should allow us to navigate to subsequent pages of information.

There is a problem with this. The list block in CRM returns a standard set of HTML to control the next, previous and other navigation within the records. So if more that one list block is rendered there will be a conflict of what the different elements in the page are called and what the different hyperlink buttons are trying to address.



But as you can see from the above diagram there must be away to allow multiple list blocks to be displayed and to navigate correctly.

What has been down is to create a page that contains one list block and an <iframe> which calls a page that displays the second list block.

The code for the wrapper page is shown below



var myOppoBlock = CRM.GetBlock('opportunitylist');
var myRecordId = CRM.GetContextInfo('company','comp_companyid');
var Arg = 'oppo_primarycompanyid='+myRecordId;
var myContentBlock = CRM.GetBlock('Content');
myContentBlock.contents = '<IFRAME FRAMEBORDER="0" MARGINHEIGHT="0" MARGINWIDTH="0" SCROLLING="NO" NORESIZE WIDTH=100% HEIGHT=400 src="'+CRM.URL("companycaselist.asp")+'"></IFrame>';
var myBlockContainer = CRM.GetBlock('Container');
with (myBlockContainer)
{
AddBlock(myOppoBlock);
AddBlock(myContentBlock);
}
CRM.AddContent(myBlockContainer.Execute(Arg));
Response.Write(CRM.GetPage());




The Inner page is much simpler. The code includes some client side javascript that makes sure the hyperlinks correctly target the main frame of CRM.


<!-- #include file ="accpaccrm.js"-->

<script>
window.attachEvent("onload",hideButton);
function hideButton()
{
var strSpan="";
var strLink="";
// hide the button
for(i=0;i<document.all.length;i++)
{
if(document.all[i].tagName=='A' )
{

document.all[i].target = "EWARE_MID";

}
}
}
</script>
<%

Response.Write(Head);

var myBlock = CRM.GetBlock('caselist');
var myRecordId = CRM.GetContextInfo('company','comp_companyid');
var Arg = 'case_primarycompanyid='+myRecordId;
Response.Write(myBlock.Execute(Arg));

%>


Note: The CRM.GetPage() method has not been used to render the page as we do not want to include the Tab bar and notifications in the inner frame.

This method is something of a cheat and there are still problems with this approach. For example thought must be made as to the target of the hyperlinks. Hyperlinks on the list block contained in the inner frame will by default target the inner frame and not the wrapper frame. This has now been addressed in the above code.

Another approach for the inner frame that can be used, is to create a new list definition in meta data and to include in the custom content of that list block the script that changes the hyperlinks in the column to target the wrapper parental frame.

I have posted an article that gives an example of a rebuild of a company quicklook screen.

But as you will see from the sample of code included in the post linked to below, the .NET API will make tasks like the rebuilding of the company quicklook easier because of the lower level control the API provides over the blocks.

Comments
  • I've noticed that this seems to have an issue with the navigation, would this be one of the quirks?

    For example, I've have a page that has list blocks in iFrames, after viewing this screen I click on the Administration button in the menu root.

    Then click back on Main Menu it will loose itself and just show the list block in the iFrame.

    Be interested to know if you have this issue, as I used my own code I wrote rather than yours, although effectively identical.

  • Hi there, I've tried your code but i couldn't seem to be able to go to the third page, it keep redirect me back to the 2nd page on clicking 'next'

  • Has anybody found a solution to  4139635's problem ... as i'm experiencing the same issue too?

  • I had a similar problem to Colborn. I followed the instructions in the above post and created a custom page with multiple list boxes. When I clicked into the details of a specific record within a list, it brought me to a new details screen - but when I clicked the Sage CRM back button, I also had the problem of being brought to a page which just showed the contents of the iFrame, omitting the rest of the page.

    I was able to solve this (for this particular situation) by adding some code to the inner page (the iFrame page). If the user ever ended up on a page which just showed the contents of the iFrame I knew they were trying to get back to the main page with the multiple lists so I forced a manual redirect. The redirect code is trigged by the URL parameter 'History' which is only present if the user clicked the CRM back button.  

    //Force redirect if user has clicked back using the CRM navigation buttons

    var strHistory = new String(Request.Querystring("History"));

    if(strHistory != "undefined")

    {

    var redirectURL = CRM.URL("Jobs/JobsQAPhase.asp?jobs_JobsID="+Id);

    Response.Redirect(redirectURL);

    }

  • I can confirm that the posted example does not let you navigate past the 2nd page of the list.

  • Kagha

    I've just tested this and the page navigation seems to be working with Sage CRM v7.1 and the above code.  What version are you testing this with?

  • Hi Jeff,

    I am working with CRM v6.2

  • I forgot to add a couple of details which might clear things up:

    The paging of the inner nested list seems to work fine (both arrows and page entry). The problem lies with the outter list contained in the main asp page. The page entry works fine but the green arrows are broken. They only go to page 1, 2 or Last.

  • I can't replicate this.  My outer page navigates correctly. Have you logged a case with you local office?  They may know whether this is a known issue with Sage CRM v6.2.

  • Thanks again for the help Jeff.

  • I may have missed something but when I select a link on the List within the iFrame, it redirects me to the linked page WITHIN the iFrame and not the outer page. I want it such that the link redirects the outer page. How can I achieve this?

  • So, I want the inner frame to redirect the outer page to the link

  • The link is corrected using this code (which is also given above)

    <script>

    window.attachEvent("onload",hideButton);

    function hideButton()

    {

    var strSpan="";

    var strLink="";

    // hide the button

    for(i=0;i<document.all.length;i++)

    {

    if(document.all[i].tagName=='A' )

    {

    document.all[i].target = "EWARE_MID";

    }

    }

    }

    </script>

  • Hi Jeff, The sorting of the columns within the iFrame does not work when I have the above script.

  • The column titles do not action the sorting when clicked.