Forum Discussion

sam_parsons's avatar
sam_parsons
Occasional Contributor
12 years ago

Scripting Issues with WaitAliasChild

Hi there,



I have another question. I've been trying to write a script, and my goal is to check if a certain link on a page exists. I have this while loop in one of my methods that looks like this:



 while(Aliases.WaitAliasChild("tasklink", 2000).Exists) {

    ...

  }




However, it is unable to find the child, so it errors out:





But the documentation for WaitAliasChild specifically says:



Result Value

The child object that has the specified alias. If the specified object does not exist, the method returns a stub object and the method does not post an error message to the log, unlike when you directly refer to a mapped object by an alias. To determine whether the returned object exists in the system, use its Exists property.



So why does it post an error message to the log? In my case, I don't want to consider not being able to find the object an error. I do not want execution to stop.



Thanks,



Samuel Parsons





10 Replies

  • sam_parsons's avatar
    sam_parsons
    Occasional Contributor
    Hi Simon,



    I tried that, but it did not fix the problem. Also, I think aliases are case-insensitive, as the documentation says:



    Note: The alias is always case-insensitive, in spite of the value of the Use case-sensitive parameters project option.



    Even if this were the problem, the Exists call should just return false. The point I'm trying to make is that WaitAliasChild is posting an error into the log when it's not supposed to.
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Samuel,



    The missing object is not the alias' target but the alias itselft. Its full path must be explicit.



    Assuming your alias is more that just "tasklink", instead of:



    Aliases.WaitAliasChild("tasklink", 2000)





    Try this considering the alias Aliases.Path.To.The.Alias.lastElementOfTheAliasPath



    Aliases.Path.To.The.Alias.WaitAliasChild("lastElementOfTheAliasPath", 2000)





    I have never tried:



    Aliases.WaitAliasChild("Aliases.Path.To.The.Alias.lastElementOfTheAliasPath")





    Sincerely
  • sam_parsons's avatar
    sam_parsons
    Occasional Contributor
    Hi Simon,



    That is the full path of the alias. I moved the alias to the top of the tree in the name mapping editor so I wouldn't have to write out a long path as you can see in this picture:







    Samuel Parsons
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Samuel,



    Aliases are case sensitive.



    In the screenshot you have TaskLink and your code has tasklink.



    Could that be the issue here ? ;-)



    Sincerely



  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Samuel,



    Sorry about the case sensivity confusion.



    I am running TC 9.2 and I wrote this to test the aliases (attached screenshot) with Acrobat Reader:

    function TestAlias()

    {

      Log.Message("Root alias");

      if(Aliases.WaitAliasChild("Acrobat_Win", 2000).Exists)

      {

        Log.Message("Found Root Alias");

      }

      else

      {

        Log.Message("NOT Found Root Alias");

      }

     

      Log.Message("Root case diff alias");

      if(Aliases.WaitAliasChild("ACROBAT_Win", 2000).Exists)

      {

        Log.Message("Found case diff Root Alias");

      }

      else

      {

        Log.Message("NOT Found case diff Root Alias");

      }

     

     

      Log.Message("Tree Alias");

      if(Aliases.AcrobatReader.WaitAliasChild("Acrobat_Win", 2000).Exists)

      {

        Log.Message("Found Tree Alias");

      }

      else

      {

        Log.Message("NOT Found Tree Alias");

      }

     

      //The following raises a JScript Error:

      //   The Aliases object does not have a child with the name "AcrobatReader.Acrobat_Win".

      /*Log.Message("Full Path Tree Alias");

      if(Aliases.WaitAliasChild("AcrobatReader.Acrobat_Win", 2000).Exists)

      {

        Log.Message("Found Full Path Alias");

      }*/ 

    }




    With Acrobat Reader not running no error is logged.



    We extensively use WaitAliasChild for it not logging any errors when the objected referenced by the alias does not exist so I am not sure what is wrong with your code.



    I learned a couple of things though.



    Sincerely
  • sam_parsons's avatar
    sam_parsons
    Occasional Contributor
    Simon,



    Right, but my concern isn't whether or not the object exists, but rather that the error is being logged. WaitAliasChild should not be logging anything.



    The end goal I want with my code is for WaitAliasChild to return a stub object as the documentation says, for the exists property to return false, and as a result the while loop would be skipped. It is not supposed to log any errors if it cannot find the object.



    Samuel Parsons
  • sam_parsons's avatar
    sam_parsons
    Occasional Contributor
    Maybe I should post all of my code so you guys can better help me out with this.





    function closeTasks() {



      var inc = 0;

      var totalRows = getTotalRows();

      var currentRow = totalRows - inc;

     

      //Close each open task

      while(currentRow != 0) {

        closeCurrentTask(currentRow);    

        inc++;

        totalRows = getTotalRows();

        currentRow = totalRows - inc;    

      }

    }



    function closeCurrentTask(rowNumber) {

        Aliases.TaskLink.href = "https://reedelsevierdev.service-now.com/sc_task.do?sys_id=*&sysparm_record_target=sc_task&"

    + "sysparm_record_row=" + rowNumber + "&sysparm_record_rows=*&sysparm_record_list=request_item%*%5EORDERBYDESCnumber";

        Aliases.TaskLink.click();

        Aliases.buttonCloseTask.click();

    }



    function getTotalRows() {

     

      //link_row represents the current row being counted. I set it to 1 at first to start    

      //counting at the first row

      var link_row = 1;  

     

    //Reset the link of the task to correspond to the current row

      Aliases.TaskLink.href = "https://reedelsevierdev.service-now.com/sc_task.do?sys_id=*&"

    + "sysparm_record_target=sc_task&sysparm_record_row="

    + aqConvert.IntToStr(link_row) + "&sysparm_record_rows=*&"

    + "sysparm_record_list=request_item%*%5EORDERBYDESCnumber";

     

      while(Aliases.WaitAliasChild("TaskLink", 2000).Exists) {

        //Next, I increment link_row so the while loop can check to see if a link to a task at the specific row exists.

        link_row++;

        Aliases.TaskLink.href = "https://reedelsevierdev.service-now.com/sc_task.do?sys_id=*"

    + "&sysparm_record_target=sc_task&sysparm_record_row="

    + aqConvert.IntToStr(link_row) + "&sysparm_record_rows=*&sysparm_record_list="

    + "request_item%*%5EORDERBYDESCnumber";    

      }



      return link_row - 1;

    }

  • sam_parsons's avatar
    sam_parsons
    Occasional Contributor
    Nevermind, I figured out a workaround with keyword tests. Thanks for the help.
    • jmcwhinney's avatar
      jmcwhinney
      Contributor

      I am struggling with the exact same issue.

      WaitAliasChild is throwing that error when according to the documentation it shouldnt.

       

      What was your workaround??

       

      Thanks!

  • I know you said "Nevermind", but I think I understand why you're getting the error in the original post. Simon was going down the right path in that the problem isn't that the waitaliaschild method isn't what's failing and posting the error, it's the object itself. I'd be willing to bet that if you went to your NameMapping and right-clicked on "TaskLink" and picked Highlight On Screen (when it's actually on the screen), you'd get an error. 



    I think you have an alias mapping issue, not a misplaced error from a method.