Tuesday, March 2, 2010

Many to Many Relationship IFrame

you can display the N-N Relationship view or any other view in CRM entity in IFrame like this:


to do this, I am creating two test entities new_testentity1 and new_testentity2 and many to many relationship between the two entities, and IFrame in new_testentity1  named IFRAME_TestEntity2
and form onload script:

function OnCrmPageLoad() {
            /* Create a N2NViewer and give it the IFRAME (container) id */
            var n2nViewer = new N2NViewer('IFRAME_TestEntity2');
            /* Set the role order - use iedevtoolber for exact parameters */
            n2nViewer.RoleOrder = 1;
            /* assing the relationship name (without the "area" word) */
            n2nViewer.TabsetId = "new_new_testentity1_new_testentity2";
            /* Do the trick... */
            n2nViewer.Load();
        }

        function N2NViewer(iframeId) {
            if (!document.all[iframeId]) {
                alert(iframeId + " is missing!");
                return;
            }

            var viewer = this;
            var _locAssocObj = null;

            viewer.IFRAME = document.all[iframeId];
            viewer.RoleOrder;
            viewer.TabsetId;

            viewer.Load = function() {
                /* Construct a valid N2N IFRAME url */
                viewer.IFRAME.src = "areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=" + crmFormSubmit.crmFormSubmitSecurity.value + "&roleOrd=" + viewer.RoleOrder + "&tabSet=area" + viewer.TabsetId;
                viewer.IFRAME.onreadystatechange = viewer.StateChanged;
            }

            viewer.StateChanged = function() {
                if (viewer.IFRAME.readyState != 'complete') {
                    return;
                }

                var iframeDoc = viewer.IFRAME.contentWindow.document;

                /* Reomve scrolling space */
                iframeDoc.body.scroll = "no";
                /* Remove crmGrid Default padding */
                iframeDoc.body.childNodes[0].rows[0].cells[0].style.padding = 0;

                /* Save MS locAssocObj */
                _locAssocObj = locAssocObj;
                /* Override MS locAssocObj */
                locAssocObj = viewer.locAssocObj;
            }

            viewer.locAssocObj = function(iType, sSubType, sAssociationName, iRoleOrdinal) {
                /* Open the Dialog */
                _locAssocObj(iType, sSubType, sAssociationName, iRoleOrdinal);
                /* Refresh only if our iframe contains the correnct tabset name */
                if (sAssociationName == viewer.TabsetId) {
                    viewer.IFRAME.contentWindow.document.all.crmGrid.Refresh();
                }
            }
        }

        //Entry Point
        OnCrmPageLoad();

No comments:

Post a Comment