Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 123975

Forum Post: Dynamic Navigation Links after UR12

$
0
0

I had this issue come up and I thought I would share.  Many of you may have seen the following code out there for doing dynamic nav links from the left navigation panel:

function SetNavigationLinks() {

     var navItem = document.getElementById('navLink{27961d03-54c9-d58c-9948-0307dce27bea}');
     if (navItem != null && navItem != undefined) {
          var u1 = encodeURI('http://<your own url>/reportservice/Pages/ReportViewer.aspx?/Sales/Quotes&rs:Command=Render&pAccount=' + Xrm.Page.getAttribute('new_accountno').getValue());
          navItem.onclick = function () { loadIsvArea(Mscrm.CrmUri.create(u1), false);};

     }

}

After UR 12 this code no longer works because loadIsvArea has been changed.

Below is the code I use now.  It shows the better way of dealing with addressing the field you want to update (this is because after almost ever UR the navLink{guid} is different for each field), the new syntax that you need for loadIsvArea, and how to deal with multiple dynamic links.

var items = Xrm.Page.ui.navigation.items.get();

for (var i in items) {
     var item = items[i];
     var itemLabel = item.getLabel();
     if (itemLabel == 'ACME Quotes') {
          var u1 = encodeURI('http://<your_own_url>/reportservice/Pages/ReportViewer.aspx?/Sales/Quotes&rs:Command=Render&pAccount=' + Xrm.Page.getAttribute('new_accountno').getValue());
          var itemObj = item.getId();
          document.getElementById(itemObj).onclick = function () {
               loadIsvArea(this,Mscrm.CrmUri.create(u1), false, new Sys.UI.DomEvent(event));
               var navIframeObject = document.getElementById(itemObj + "AreaFrame");
               navIframeObject.src = u1;
          };
     } else {
          if (itemLabel == 'ACME Orders') {
          var u2 = encodeURI('http://<your_own_url>/reportservice/Pages/ReportViewer.aspx?/Sales/Orders&rs:Command=Render&pAccount=' + Xrm.Page.getAttribute('new_accountno').getValue());
          var itemObj2 = item.getId();
          document.getElementById(itemObj2).onclick = function () {
               loadIsvArea(this,Mscrm.CrmUri.create(u2), false, new Sys.UI.DomEvent(event));
               var navIframeObject2 = document.getElementById(itemObj2 + "AreaFrame");
               navIframeObject2.src = u2;
               };
          }
     }
}

Please note though this is NOT SUPPORTED by Microsoft.

Here is a quote from MS on this: 

"This code is not supported. It is not supported to call Mscrm.CrmUri.create, also it is not supported to access object in dom directly using getElementById. Finally you are attaching event handlers which are not supported."

That being said though at this time I know of no other way to handle this in a supported manner so this is all I have to go with at this time.

I hope this helps anyone that needs it.  I saw many posts through Google and Bing about the old way, but zero on the "fix".


Viewing all articles
Browse latest Browse all 123975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>