8 Replies Latest reply: Jun 6, 2013 1:27 PM by Phaithoon RSS

    Need to reference User's PKID for Navigation button

    Phaithoon
      Dear All,


      We try to create the new application which require to receive the user's PKID from PLM System. I try to follow the instruction from the Navigation Configuration User guide contained inside EP2.5, but it's nothing return after configure. I think the EP2.5 is used only 6.1 version upward, but we're in older version.

      We start modifing the default.aspx by including the namespace below

      <%@ Import Namespace="Xeno.Prodika.Application" %>
      <%@ Import Namespace="Xeno.Prodika.Services" %>

      and create the new javascript function inside that default.aspx file like

      function GetUserPKID()
      {
      return "<%=AppPlatformHelper.ServiceManager.GetServiceByType<IUserService>().UserContext.User.PKID %>";
      }

      </script>

      And also modify the SiteMap-Extensions.xml by including the javascript function while during new window open after clicking that menu name “lblTest”

      <MenuItem ID="lblTest" DisplayText="--Template Maintenance" SecurityProfileRef="" SkinRef="DefaultSkin" configChildKey="ID" ClientSideCommand="window.open('http://vm-cpt-plmuat03.cpf.co.th:8080/CPFRPT/OTIF.aspx?UserID=' + GetUserPKID();" />

      After restart IIS, I found the error message during recompile like method “GetServiceByType” is not available inside AppPlatformHelper.ServiceManager.

      AppPlatformHelper.ServiceManager.GetServiceByType<IUserService>().UserContext.User.PKID

      So my colleague and me try to find out the another namespace which I can use the method like “GetServiceByType” like above, we found this

      Xeno.Prodika.Services.UserService.UserServiceHelper.GetUserContext().User.PKID


      The above method can helping us to get the user’s PKID, so I decide to put those statement into javascript function instead of the old one like below

      function GetUserPKID()
      {
      //return "<%=AppPlatformHelper.ServiceManager.GetServiceByType<IUserService>().UserContext.User.PKID %>";
      var user_id = <%=Xeno.Prodika.Services.UserService.UserServiceHelper.GetUserContext().User.PKID %>";
      return user_id;
      }

      </script>

      I insert the comment tag, with old return command, and put my new method by assigning into user_id and return back the user's PKID while using "GetUserPKID" function from menu.


      I think, it should be okay for us, becuase it can return the right user's PKID when looking at the source code by using View>>Source inside IE menu. But there are nothing happen after clicking this new menu, no progress bar show, nothing happen. Can you please guiding me how I can get through this issue?

      Thank you so much in advance for your helping.
        • 1. Re: Need to reference User's PKID for Navigation button
          Ron M-Oracle
          You can try the following
          ((IUserService)AppPlatformHelper.ApplicationManager.ServiceManager[typeof(IUserService).FullName]).UserContext.User.PKID
          instead of
          AppPlatformHelper.ServiceManager.GetServiceByType<IUserService>().UserContext.User.PKID 
          But the reason the Javascript isn't working is that you placed it into default.aspx, rather than one of the aspx or ascx files that it would get called from.
          If you are calling this from within UGM, for example, then you would probably need to add it to Main\Main.aspx

          ---
          Also: remember that this is a custom solution that you have to maintain through upgrades. I am not sure if the 6.1 release includes the UserID as data for the GetObjectHeader_ObjectPKID() function. If it does, then when you upgrade to 6.1, you can remove your custom solution, changing the navigation button extension to use the supported function, rather than yours.
          • 2. Re: Need to reference User's PKID for Navigation button
            Phaithoon
            Hi Ron,

            Thank you so much for your suggestion, right now i change my javascript function into

            <script language="javascript">     
                 
                 function GetUserPKID()
                 {
                 return "<%=((IUserService)AppPlatformHelper.ApplicationManager.ServiceManager[typeof(IUserService).FullName]).UserContext.User.PKID%>";
                 }

            </script>

            like your suggestion and it can return the pkid, which i can see the user pkid from view>> source under IE menu obviously.
            But i still got stuck with the javascript, it's still not working event i put my script inside UGM/Main/main.aspx page.

            Where is the place i should place my javascript into? right now i put my javascript inside <Header> tag.
            • 3. Re: Need to reference User's PKID for Navigation button
              Ron M-Oracle
              So when you click on your new Navigation entry, is it not calling the function at all? But you say the javascript is on the page when you view source?
              If you put an Alert('my function!') first in the GetUserPKID function, is that showing up when you click the nav entry?
              Can you move the script out of the <header> tag and try too?
              • 4. Re: Need to reference User's PKID for Navigation button
                Phaithoon
                Let me answer your question one by one.
                So when you click on your new Navigation entry, is it not calling the function at all?
                Yes, it's nothing working after clicking new new menu.

                But you say the javascript is on the page when you view source?
                Yes, i see the user pkid when viewing the source code, but i don't know why it can show and passing that value while clicking my new menu.
                Here is my menu inside menu extension.

                <MenuItem ID="lblTest" DisplayText="--Template Maintenance" SecurityProfileRef="" SkinRef="DefaultSkin" configChildKey="ID" ClientSideCommand="window.open('http://vm-cpt-plmuat03.cpf.co.th:8080/CPFRPT/OTIF.aspx?UserID=' + GetObjectHeader_ObjectPKID();" />

                Is it correct?

                If you put an Alert('my function!') first in the GetUserPKID function, is that showing up when you click the nav entry?
                No, it is nothing return

                Can you move the script out of the <header> tag and try too?
                I also move my script out of header section, but it's remain the same.

                <script language="javascript">     
                     
                     function GetUserPKID()
                     {
                     Alert('my function!')

                     return "<%=((IUserService)AppPlatformHelper.ApplicationManager.ServiceManager[typeof(IUserService).FullName]).UserContext.User.PKID%>";
                     }

                </script>
                • 5. Re: Need to reference User's PKID for Navigation button
                  Phaithoon
                  Sorry i put the wrong one

                  here is my configuration in menu extension
                  <MenuItem ID="lblTest" DisplayText="--Template Maintenance" SecurityProfileRef="" SkinRef="DefaultSkin" configChildKey="ID" ClientSideCommand="window.open('http://vm-cpt-plmuat03.cpf.co.th:8080/CPFRPT/OTIF.aspx?UserID=' + GetUserPKID();" />
                  • 6. Re: Need to reference User's PKID for Navigation button
                    Ron M-Oracle
                    Your menu item is still referencing the other Javascript function, GetObjectHeader_ObjectPKID(), instead of your new one, GetUserPKID().

                    You could either change the name of your function GetUserPKID to GetObjectHeader_ObjectPKID():
                    function GetObjectHeader_ObjectPKID()
                    {
                       Alert('my function!')
                    
                       return "<%=((IUserService)AppPlatformHelper.ApplicationManager.ServiceManager[typeof(IUserService).FullName]).UserContext.User.PKID%>";
                    }
                    or change your menu item to call GetUserPKID():
                    <MenuItem ID="lblTest" DisplayText="--Template Maintenance" SecurityProfileRef="" SkinRef="DefaultSkin" configChildKey="ID" ClientSideCommand="window.open('http://vm-cpt-plmuat03.cpf.co.th:8080/CPFRPT/OTIF.aspx?UserID=' + GetUserPKID() ) ; " />
                    Edited by: Ron M on Jun 6, 2013 1:07 PM

                    --->>> I think your window.open was also missing a closing parenthis
                    • 7. Re: Need to reference User's PKID for Navigation button
                      Ron M-Oracle
                      I submitted the last reply before I saw your correction. So what I wrote doesn't apply, but it did look like you were missing a closing parenthesis in the window.open command. See if adding that fixes the issue.
                      • 8. Re: Need to reference User's PKID for Navigation button
                        Phaithoon
                        Hi Ron,

                        It is working now, it's because i forget the "parenthesis" inside menu extension file. Thank you so much for your help.

                        Best Regards,
                        Phaithoon W.