CA Service Management

  • 1.  We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 22, 2014 03:47 AM

     

    Hi,

     

    we have the following code in our USD 12.7 environment.

    It is working fine in Chrome, Firefox, Opera, Safari.

    But it not working in Internet Explorer (version 10 and 11).

     

    After a lot of testing, I could find out the second display_new_page is not called as it should be.

    As you can see in the code below, I added an alert to the function to check if the function is called, but the alert is not triggered in IE.

    By adding extra alerts, I was able to find out these steps are done in IE:

     

     

    z_add_chassloc() is called.

     

    From within this function the display_new_page is executed and z_add_chassloc2(persid,value,rel_attr_val) is started.

     

     

    And here is where it stops.

     

    The display_new_page in this function is not executed in Internet Explorer.

     

     

    Like I already said, this problem occurs only in Internet Explorer. Every other browser is working fine.

     

     

     

    [codebox]

     

    var ch_loc = "";

     

     

     

    function z_add_chassloc(){

     

                var zFID=document.forms["main_form"].elements["FID"].value;

     

                var zSID=document.forms["main_form"].elements["SID"].value;

     

                var url2;

     

                url2=cfgCgi+"?SID="+zSID+"+FID="+zFID

     

        +"+OP=SEARCH+FACTORY=nr"

     

        +"+KEEP.domset_name=RLIST_STATIC"

     

        +"+QBE.EQ.zUsedByCI="+escape('$args.id')

     

        +"+KEEP.special_lookup=1"

     

                +"+KEEP.backfill_attr=zChassis.id"

     

        +"+HTMPL=javascript:parent.ahdframe.z_add_chassloc2";

     

                display_new_page(url2,ahdframeset.workframe);

     

    }

     

     

     

     

     

    function z_add_chassloc2(persid,value,rel_attr_val){

     

               

     

               var zFID=document.forms["main_form"].elements["FID"].value;

     

                var zSID=document.forms["main_form"].elements["SID"].value;

     

                var url3;

     

                url3=cfgCgi+"?SID="+zSID+"+FID="+zFID

     

        +"+OP=SEARCH+FACTORY=nr"

     

        +"+KEEP.domset_name=RLIST_STATIC"

     

        +"+QBE.EQ.id="+escape(value)

     

        +"+KEEP.special_lookup=1"

     

                +"+KEEP.backfill_attr=zCMDBLocation.zName"

     

        +"+HTMPL=javascript:parent.ahdframe.z_add_chassloc3";

     

                display_new_page(url3,ahdframeset.workframe);

     

    }

     

     

     

    function z_add_chassloc3(persid,value,rel_attr_val){

     

                alert("test");

     

                if (value.toString() != ""){

     

                            ch_loc = value;

     

                }else{

     

                            ch_loc = "";

     

                }

     

               

     

                document.getElementById('chassloc').innerHTML = ch_loc;

     

               

     

    }

     

    [/codebox]

     



  • 2.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 22, 2014 05:06 AM

    Hi.

     

    I have no idea, why IE dos not submit your second http request. Maybe this is related to the workframe you are using, which is in use by other background mechanism too, and I can imagine different timings in different browsers.

     

    Anyway, I think, your code can be streamlined a bit, so the second http request is not needed.

    This is my understanding:

    • there are three assets involved, ci1, ci2 and ci3
    • You starting point is ci1
    • In your first request, you are looking for the value of the Attribute "zChassis.id" of asset ci2, which references ci1 in its zUsedByCI attribute.
    • "zChassis.id" itself is the uuid of ci3.
    • In your second http request, your are looking for the value of the attribute "zCMDBLocation.zName" of ci3.

     

    I think, this can be done in one http request. Because zChassis seems to be an SREL, you would be able to do something like:

    var ch_loc = "";
    function z_add_chassloc(){
        
        var zFID=document.forms["main_form"].elements["FID"].value;
        var zSID=document.forms["main_form"].elements["SID"].value;
        var url2;
        url2=cfgCgi+"?SID="+zSID+"+FID="+zFID
            +"+OP=SEARCH+FACTORY=nr"
            +"+KEEP.domset_name=RLIST_STATIC"
            +"+QBE.EQ.zUsedByCI="+escape('$args.id')
            +"+KEEP.special_lookup=1"
            +"+KEEP.backfill_attr=zChassis.zCMDBLocation.zName"
            +"+HTMPL=javascript:parent.ahdframe.z_add_chassloc3";
    
        display_new_page(url2,ahdframeset.workframe);
    } 
    function z_add_chassloc3(persid,value,rel_attr_val){
        alert("test");
        if (value.toString() != ""){
            ch_loc = value;
        }else{
            ch_loc = "";
        }
        document.getElementById('chassloc').innerHTML = ch_loc;
    }
    


    Give it a try and let me know your thoughts.

    Kind regards

    ...........Michael



  • 3.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 22, 2014 07:50 AM

    Hi Michael

     

    In this case, we were helped by your remark and we were able to limit the lookup to a single display_new_page.

     

    However,

    In another customization, we still need a double lookup, because we need multiple records from an item.

    So we need to do 2 lookups, to find the needed information.

     

    Here also, we have the issue that the second display_new_page is not called in Internet Explorer, while it will work in other browsers.

     

    Thank you,

    Sandra



  • 4.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 23, 2014 03:46 AM

    Hi Sandra.

    There are allways different options to reach a certain goal. Thinking about your original problem, I also have an idea in mind, where not even one additional http request is needed. And I can imagine options, where you can also get more than one value/record wihout doing an additonal hztp request for each value you need. It always dependes on your requirements. In the meantime I'm quite sure, that your IE problem is related to the use of this workframe. As said before, the workframe is in use by other background actions also, and therefor, you may run into the situation, where two threads are using the same workframe, and this can not work because only one can win.

    One solution would be to use ajax calls instead. This will give you full control over your http requests. However, maybe there is not even one additonal request needed. It depends.

    • In which situation do you need this additional information?
    • When you load a certain form?
    • Or when a user enters some value to a simple text field?
    • Or after the GUI did a lookup for a specific looktup field after the user entered some value?

    Kind regards

    ............Michael



  • 5.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 23, 2014 06:20 AM

    Hi Michael,

     

    Thank you for the feedback. Indeed there might be a way to do it in one http request. But we are not able to found one.

    Maybe we can share knowledge and you can have a look?

     

    Hereby the code:

    We have a lookup and after this lookup was updated, we need a check on certain restrictions:
    This is the lookup:

    <PDM_MACRO name=dtlLookup hdr="CMDB Location" attr="zCMDBLocation" evt="onBlur='z_check_location(this)'" size=100>

     

    These are the functions used (the general variables were declared before off course)

    function z_check_location(field){
    //        alert("1");
                var formulier = document.forms["main_form"];
                var checkloc = formulier.elements["SET.zCMDBLocation"];
               var zFID=document.forms["main_form"].elements["FID"].value;
                var zSID=document.forms["main_form"].elements["SID"].value;
                var url;
                url=cfgCgi+"?SID="+zSID+"+FID="+zFID
        +"+OP=SEARCH+FACTORY=zCMDBLocation"
        +"+KEEP.domset_name=RLIST_STATIC"
        +"+QBE.EQ.id="+escape(checkloc.value)
        +"+KEEP.special_lookup=1"
                +"+KEEP.backfill_attr=zRoomType.zSymbol"
        +"+HTMPL=javascript:parent.ahdframe.z_check_location2";
                display_new_page(url,ahdframeset.workframe);
    }

    function z_check_location2(persid,value,rel_attr_val){
                //alert("3");
                ci_new_loc_roomtype = value;
                var formulier = document.forms["main_form"];
                var checkloc = formulier.elements["SET.zCMDBLocation"];
               var zFID=document.forms["main_form"].elements["FID"].value;
                var zSID=document.forms["main_form"].elements["SID"].value;
                var url;
                url=cfgCgi+"?SID="+zSID+"+FID="+zFID
        +"+OP=SEARCH+FACTORY=zCMDBLocation"
        +"+KEEP.domset_name=RLIST_STATIC"
        +"+QBE.EQ.id="+escape(checkloc.value)
        +"+KEEP.special_lookup=1"
                +"+KEEP.backfill_attr=tenant.name"
        +"+HTMPL=javascript:parent.ahdframe.z_check_location3";
                display_new_page(url,ahdframeset.workframe);
    }


    function z_check_location3(persid,value,rel_attr_val){
                ci_new_loc_tenant = value;
                //alert ("roomtype = " + ci_new_loc_roomtype + "\ntenant = " + ci_new_loc_tenant);
                if (ci_new_loc_tenant == "Cegeka Service Provider" && ci_new_loc_roomtype == "Computer room" && role_allowed < 10){
                            var formulier = document.forms["main_form"];
                            var checkloc = formulier.elements["SET.zCMDBLocation"];
                            var checkloc2 = formulier.elements["KEY.zCMDBLocation"];
                            checkloc.value = "";
                            checkloc2.value = "";
                            checkloc2.focus();
                            alert("You are not allowed to change the location to the Cegeka datacenter");
                }
    }


    Both http requests use the value of the lookup field as a filter.
    The first lookup is to request the custom field roomtype, the second lookup is used to request the tenant. (the custom table zCMDBLocation is tenant required)


    Is there a way to add a sort of timeout to the workframe so that IE does not have this issue, or maybe it is possible to add a second workframe, so all browsers use the second frame to do the second http request?



  • 6.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?
    Best Answer

    Posted Oct 23, 2014 12:11 PM

    Hi Sandra.

    One possible way to fetch information on the fly, is using ajax and JSON. Ajax will give you full control to your http request, while JSON is an ideal transport layer for data.

    So how does it work in general:

    • You build up a URL, similar as you did before, which will execute a search operation.
    • By specifying a specific HTMPL template in this URL, you can define, how the result is processed.
    • Then you call this URL with the help of an Ajax functions.
    • The specific HTMPL template will generate JSON code, which gets delivered back to your calling javascript function.
    • Then you do an eval on the result, and you will have a javascript object with all the information available.

     

    In detail:

    • You need a new htmpl file which will generate your json code. Lets call it "list_zCMDBLocation_json.htmpl" with the following content:

       

      {
          "records" : [
      <PDM_LIST SOURCE=list SORT=$sort START=$start ESC_STYLE=C>
          <PDM_IF $list.ROW \> 0>,</PDM_IF>
          {
            "roomtype"   : '<PDM_FMT ESC_STYLE=JS2>$list.zRoomType.zSymbol</PDM_FMT>',
            "tenantname" : '<PDM_FMT ESC_STYLE=JS2>$list.tenant.name</PDM_FMT>'
          }
          </PDM_LIST>
        ]
      }
      

     

     

    • The building of the URL, the ajax call, and the evalutaion of the result may look like:
      url=cfgCgi+"?SID="+cfgSID+"+FID="+fid_generator()+
          "+OP=SEARCH+FACTORY=zCMDBLocation" +
          "+QBE.EQ.delete_flag=0" +
          "+QBE.EQ.id="+escape(checkloc.value)
          "+HTMPL=list_zCMDBLocation_json.htmpl";
      result = SyncAjaxCall(url, "GET");
      result = result.substring(result.indexOf("{"));
      if( result.charCodeAt(result.length-1) == 0 ) {
          result = result.substr(0, result.length-1);
      }
      data = eval('(' + result + ')');
      

     

     

    • now you can access your information with:
      ci_new_loc_roomtype = data.records[0].roomtype;
      ci_new_loc_tenant   = data.records[0].tenantname;
      

     

    This kind of implementation has two advantages: Being independent from any workframe and fetching all needed data at once.

    Further on, the same principle can be used to fetch more than one record. You may have recognized, that data.records is an array.

     

    I also had some other ideas:

    • The onBlur event gets triggered in the same moment, when the standard onChange event gets triggered also. The onChange event tries to do a lookup with the value entered into the visible field, while your onBlur event tries to do your stuff. I see two problems here:
      • This is exactly the race condition which may lead to the non functional IE, because both things may use the same workframe more or less at the same time.
      • When you are reading the value of "SET.zCMDBLocation", you may get an old value, because the lookup is not yet finnished.
        • Maybe its better to use the function backfill_event, which gets executed (if defined) when the standard lookup is done.
    • Why letting the user first search and select something, and after that, telling him, that he is not allowed to do so. What do you think about a different approach: The user can only search for and select CMDBLocations he is allowed to select. So he can not run into a situation, where the system says "no".
      • This could be achieved by using the extraURL parameter in the dtlLookup macro. But I think, there would be some additional work to do, to make it waterproofed.

     

    Kind regards and let me know your thoughts.

    ............Michael



  • 7.  Re: We encounter an issue with customized code not working in every browser except for Internet Explorer. Has anyone encountered the same issue?

    Posted Oct 24, 2014 02:59 AM

    HI Michael,

     

    Thanks a lot for all the support.

    My colleague tested your proposal and it works!

    (Now a world of new solutions opens for us, we kept on struggling with javascript, but now we now JSON works as well )

     

    Thank you,

    Sandra