locked
Strange thing is happening in my code...pleae help me RRS feed

  • Question

  • Hi all,

     

    There is something strange that is happening on my code !!!

    Could anybody pleasse help me ???

     

    in case form, i need to hide the followup icon for a specific security role, but for another security role i need to hide the followup icon and the action menu:

     

    so ihave written the following javascript in the onLoad event:

     

     

            if(UserHasRole("security role 1"))  //the security role for which i need to hide the followup icon

            {

    function OnCrmPageLoad() { // Remove Spacers: var imgs = document.getElementsByTagName('IMG'); var j = 0; while(j<imgs.length) { if(imgs[j].id == 'mnu_hSpacerGrid') { imgs[j].parentNode.outerHTML = "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>"; } j=j+1; } // Company toolbar buttons //ShowHideToolbarButton( "_MBcrmFormSubmitCrmForm59truetruefalse",3 ); // Save and New //ShowHideToolbarButton( "_MBcrmFormPrint",3 ); // Print Preview //ShowHideToolbarButton( "_MBlocAddActTo4202",4 ); // Send E-mail //ShowHideToolbarButton( "_MBlocAddFileTo5", 4 ); // Add attachment //ShowHideToolbarButton( "Reports" , 4); //Reports //ShowHideToolbarButton( "action" , 4); //Action ShowHideToolbarButton( "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup" , 4); //Follow Up function ShowHideToolbarButton( btnId, span ) { if(document.getElementById(btnId)!=null) { switch(span) { case 3: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>"; break; case 4: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN> </SPAN>"; break; } } }

    } window.onresize = OnCrmPageLoad; OnCrmPageLoad(); ////////////////////////////////////////////////////////end of remove toolbar icon////////////////////////////////////////////////// }

     

    else if(UserHasRole("security role 2"))  //the security role for which i need to hide the followup icon and the action menu

            {

    function OnCrmPageLoad() { // Remove Spacers: var imgs = document.getElementsByTagName('IMG'); var j = 0; while(j<imgs.length) { if(imgs[j].id == 'mnu_hSpacerGrid') { imgs[j].parentNode.outerHTML = "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>"; } j=j+1; } // Company toolbar buttons //ShowHideToolbarButton( "_MBcrmFormSubmitCrmForm59truetruefalse",3 ); // Save and New //ShowHideToolbarButton( "_MBcrmFormPrint",3 ); // Print Preview //ShowHideToolbarButton( "_MBlocAddActTo4202",4 ); // Send E-mail //ShowHideToolbarButton( "_MBlocAddFileTo5", 4 ); // Add attachment //ShowHideToolbarButton( "Reports" , 4); //Reports ShowHideToolbarButton( "action" , 4); //Action ShowHideToolbarButton( "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup" , 4); //Follow Up function ShowHideToolbarButton( btnId, span ) { if(document.getElementById(btnId)!=null) { switch(span) { case 3: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>"; break; case 4: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN> </SPAN>"; break; } } }

    } window.onresize = OnCrmPageLoad; OnCrmPageLoad(); ////////////////////////////////////////////////////////end of remove toolbar icon////////////////////////////////////////////////// }

     

    but for some reason the action menu is not shown for both users !!!

    Is there something wrong on my code ???

     

    Please note that i have retrieved the current user security role using a function that have been posted in the forum and i've test it in a more simple example and it's working

    and the function to hide the toolbar icons also has been tested in a simpler example and it's working too.

     

    any help will be appreciated,

     

    thanks in advance 

    Saturday, October 23, 2010 1:19 PM

Answers

  • Hi,

    You just need to rename your functions. Don't use same function name for more than one function within the same scope. In your case the two functions which you have defined for the "second role" condition will be called everytime i.e for "first role" codition also.

    My suggestion is don't define functions in the if else condition blocks. Instead define them seperately and call them in your condition blocks. Something like below:

    ShowHideToolbarButton( btnId, span )

    {

    if

     

    (document.getElementById(btnId)!=null)

    {

    switch

     

    (span)

    {

    case

     

    3:

    document.getElementById(btnId).outerHTML =

    "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>";

    break

     

    ;

    case

     

    4: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN> </SPAN>";

    break

     

    ;

    }

    }

    }

    function

     

    OnCrmPageLoad() { // Remove Spacers:

     

    var imgs = document.getElementsByTagName('IMG');

     

    var j = 0;

     

    while (j < imgs.length) {

     

    if (imgs[j].id == 'mnu_hSpacerGrid') {

    imgs[j].parentNode.outerHTML =

    "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>";

    }

    j = j + 1;

    }

    }

    function

     

    CheckRoles() {

     

    if (UserHasRole("security role 1")) //the security role for which i need to hide the followup icon

    {

    ShowHideToolbarButton(

    "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup", 4); //Follow Up

    }

     

    else if (UserHasRole("security role 2")) //the security role for which i need to hide the followup icon and the action menu

    {

    ShowHideToolbarButton(

    "action", 4);

    ShowHideToolbarButton(

    "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup", 4); //Follow Up

    }

    }

    CheckRoles();

    window.onresize =

    function() {

    CheckRoles();

    }


    Vicky http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"
    Saturday, October 23, 2010 6:33 PM

All replies

  • It is already answered please refer to this post
    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Mark as answer if a post has answered the question
    Saturday, October 23, 2010 2:06 PM
  • Dear Amol,

     

    Would you please help me writing this code ??

     

    thanks in advance

    Saturday, October 23, 2010 4:56 PM
  • Hi,

    You just need to rename your functions. Don't use same function name for more than one function within the same scope. In your case the two functions which you have defined for the "second role" condition will be called everytime i.e for "first role" codition also.

    My suggestion is don't define functions in the if else condition blocks. Instead define them seperately and call them in your condition blocks. Something like below:

    ShowHideToolbarButton( btnId, span )

    {

    if

     

    (document.getElementById(btnId)!=null)

    {

    switch

     

    (span)

    {

    case

     

    3:

    document.getElementById(btnId).outerHTML =

    "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>";

    break

     

    ;

    case

     

    4: document.getElementById(btnId).outerHTML = "<SPAN> <SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN> </SPAN>";

    break

     

    ;

    }

    }

    }

    function

     

    OnCrmPageLoad() { // Remove Spacers:

     

    var imgs = document.getElementsByTagName('IMG');

     

    var j = 0;

     

    while (j < imgs.length) {

     

    if (imgs[j].id == 'mnu_hSpacerGrid') {

    imgs[j].parentNode.outerHTML =

    "<SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN>";

    }

    j = j + 1;

    }

    }

    function

     

    CheckRoles() {

     

    if (UserHasRole("security role 1")) //the security role for which i need to hide the followup icon

    {

    ShowHideToolbarButton(

    "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup", 4); //Follow Up

    }

     

    else if (UserHasRole("security role 2")) //the security role for which i need to hide the followup icon and the action menu

    {

    ShowHideToolbarButton(

    "action", 4);

    ShowHideToolbarButton(

    "_MBdocumentallRelatedInformationPaneExpanddocumentallRelatedInformationPaneLoadContextDatafollowup", 4); //Follow Up

    }

    }

    CheckRoles();

    window.onresize =

    function() {

    CheckRoles();

    }


    Vicky http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"
    Saturday, October 23, 2010 6:33 PM
  • Using above code, it will slightly tough as you need to store the outerHTML to some temporary variable and then again assign back to control.

    I would recommend you to use code from below link which is by written Adi

    http://mscrm4ever.blogspot.com/2008_08_01_archive.html

    For Hiding, you will write

     ShowHideToolbarButton( "Follow Up"  , Spacer.Right , Display.Hide);

    For showing you will write

     ShowHideToolbarButton( "Follow Up"  , Spacer.Right , Display.Show);

     

     


    Jai Ho CRM http://mscrmkb.blogspot.com Skype - amol.gholap

    Mark as answer if a post has answered the question
    Saturday, October 23, 2010 6:50 PM