CA Service Management

 View Only
  • 1.  Condition Based on the URL - "window.location.hostname"

    Posted Aug 15, 2016 05:10 PM

    Guys!!!

    Theres a way to show or hide an element on employee interface based on the url?

    I can do some activities with javascript using "window.location.hostname" arg on the analyst form.

    On the analyst form i use the code below and it work perfectly:

    if (window.location.hostname == "10.0.0.1"){
    <PDM_MACRO name=dtlHier hdr="Category" attr=category>
    }else{
    <PDM_MACRO name=dtlHier hdr="Category 2" attr=category>
    }
    

    I need, plus some other things, change the ${ProductName} value on the login.htmpl form based on the url it is accessed, but on the employee htmpl code i cannot use the "window.location.hostname".

    I try to use the code below but didint worked!

    <PDM_IF window.location.hostname == "10.61.0.54">
    <td width="367" height="53" class="login_productname">${ProductName}</td>
    <PDM_ELSE>
    <td width="367" height="53" class="login_productname">ANOTHER VALUE</td>
    </PDM_IF>
    

    I think that the "window.location.hostname" arg is not recognized by the form, or the most probable, im doing something wrong.

    I create a variable with the "window.location.hostname" args and call him on a condition with "PDM_IF", but didint worked too!

    var zlocation = window.location.hostname;
    .
    .
    .
    .
    .
    <PDM_IF zlocation == "10.61.0.54">
    <td width="367" height="53" class="login_productname">${ProductName}</td>
    <PDM_ELSE>
    <td width="367" height="53" class="login_productname">ANOTHER VALUE</td>
    </PDM_IF>
    

    Can anyone help?!



  • 2.  Re: Condition Based on the URL - "window.location.hostname"
    Best Answer

    Posted Aug 16, 2016 03:21 AM

    Hello Diego,

     

    Maybe try this post here and see if it helps?

    ___________

    I used UrlRewriteFilter from http://tuckey.org/urlrewrite/ with my tomcat and condition based on "host" (not listed in Possible Values list, but used in example)

    www.example.com">operator="notequal">www.example.com

    ___________

     

    Bit of a long shot, as it looks like he got "window.location.hostname" working fine - and didn't specify whether it was Analyst or Employee web interface. If it was the Analyst interface then there may be no new information there, but you may glean something.

    It's good to know that someone else has been tackling the same issue at any rate.

     

    Hello CA Service Management - any suggestions for Diego welcome. Has anyone modified the Employee web form and done a lookup for the URL?

     

    Kyle_R.



  • 3.  Re: Condition Based on the URL - "window.location.hostname"

    Posted Aug 18, 2016 03:09 PM

    Hi Kyle_R!!

    Many thanx for answer!!

    I downloaded the urlrewriter but didn't configured yet.

    Im thinking.. if theres a way to create a variable like "cfgProductName = "$ProductName"" on one of the .js files to store the value of the url and call this var on a condition in these forms, like:

    ztest.js (or another .js file)

     

    zhost = window.location.hostname;
    

     

    Add the ztest.js on the login.htmpl form for example:

     

    <script type="text/javascript" src="$CAisd/scripts/ztest.js"></script>
    

     

    And call the variable on my condition:

     

    <PDM_IF "$zhost" == "10.0.0.0">
    <td width="367" height="53" class="login_productname">${ProductName}</td>
    .
    .
    .
    .
    .
    
    

     

    I 'm not really sure if what I 'm thinking makes sense, but for a moment thought I could solve the need this way...



  • 4.  Re: Condition Based on the URL - "window.location.hostname"

    Posted Aug 19, 2016 11:29 AM

    Please understand the difference between client side actions and server side actions. The "if () construct is Javascript and client side. the "PDM_IF" construct is pre-processor and server side. The following code will not work because window.location.hostname is a client side value and does not exist at the server side.

     

    <PDM_IF window.location.hostname == "10.61.0.54">



  • 5.  Re: Condition Based on the URL - "window.location.hostname"

    Posted Aug 19, 2016 02:49 PM

    Got it!!! =(