Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
9 years ago

JScript runtime error: is null or not an object

I am using the FindChild Method to find a name in a table on a WEB page.

Sometimes the name will be there and sometimes it will not.

When it is there everything is good. When the name does not exist I get the JScript runtime error because the object is null or not an object.

 

How can I gracefully handle the time when the name is not there in order to avoid the runtime error?

 

Here is the code:

 

//Variables for the Admin name
var Adminprops = new Array("innerText", "Visible", "VisibleOnScreen");
var values = new Array(AdminName, true, true);
var users = Aliases.CTXBOHpageCatertraxComShopad.CTXBOHframeMainframe.CTXBOHAdmintable;
var userexists = users.FindChild(Adminprops, values, 30);

//Variable for the admin state color
var Admincolor = new Array("innerText","ObjectType", "Visible", "VisibleOnScreen");
var namecolor = new Array(AdminName,"TextNode", true, true);
var userstates = Aliases.CTXBOHpageCatertraxComShopad.CTXBOHframeMainframe.CTXBOHAdmintable;
var StateOfUser = userstates.FindChild(Admincolor, namecolor, 30);

// Log.Message(userexists)

if(userexists.Exists){
//If the user exists then check what state it is in
if(StateOfUser.color == "#000000") {
// Log.Message("Color = #000000");
AdminState = "EXISTS";
}
else if(StateOfUser.color == "#bbbbbb"){
// Log.Message("Color = #bbbbbb");
AdminState = "DELETED";
}
}
else{
//Cannot find the specified Admin so presuming that the Admin does not exist in the table
//If the user does not exist then set AdminState = NOTTHERE
AdminState = "NOTTHERE";
Log.Message(AdminState)
}
return AdminState;
}

  • Where in the code are you getting the JScript error?  As it is, userexists.Exists should return a boolean false so you shouldn't get an error there so I'm curious as to what line is actually popping your error message.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Where in the code are you getting the JScript error?  As it is, userexists.Exists should return a boolean false so you shouldn't get an error there so I'm curious as to what line is actually popping your error message.

    • kevin_kapell's avatar
      kevin_kapell
      Frequent Contributor

      So now I am confused and a little embarrassed as the code is no longer throwing an error. I wonder if I had something cached?

      Anyway i am going to close this as resolved. Thanks for your response.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        No worries.  If it pops up again, you know where to find us. :)