Forum Discussion

kankele's avatar
kankele
Occasional Contributor
10 years ago

Project Variables of type Object

I'm trying to better understand working with Project Variables of type object in JScript. Could someone help me understand why the last couple of lines throw an exception.

 

function main()
{
   var item = {};
   item.sku = "11111";
   item.description = "222222";
   Project.Variables.ItemDef = item;   // Project.Variables.ItemDef is defined as a temporary variable of type object in the project
   item.location = "3333";
   
 //  Project.Variables.ItemDef.city = "4444";   // this line throws an exception 
   
   var item2 = Project.Variables.ItemDef;
   item2.state = "5555";  // this line also throws an exception
}

 

Thanks!

 

Ken

 

  • One of my colleagues (thanks Helen!) points out that this was a bug in TestComplete 8 and fixed in TestComplete 9.  Sure enough, it fails for me when I try it in TestComplete 8.  No known workaround.

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    Perhaps I'm missing something here, but it seems you are trying to set the property "city" for object "item" without first defining that property.

     

    function main()
    {
       var item = {};
       item.sku = "11111";
       item.description = "222222";
       item.city = ""; //added
       item.state = ""; //added
       item.location = "3333"; //moved
    
       /*
         item has now been fully defined
         set ItemDef project variable as object item
       */
       Project.Variables.ItemDef = item;     
    
       Project.Variables.ItemDef.city = "4444";
       
       var item2 = Project.Variables.ItemDef;
       item2.state = "5555";
    }

     

    • kankele's avatar
      kankele
      Occasional Contributor

      Ryan - Javascript allows you to add properties dynamically

      • joseph_michaud's avatar
        joseph_michaud
        Moderator

        One of my colleagues (thanks Helen!) points out that this was a bug in TestComplete 8 and fixed in TestComplete 9.  Sure enough, it fails for me when I try it in TestComplete 8.  No known workaround.

  • Interesting.  I don't get any exceptions thrown.  What version of TestComplete and Windows OS are you using?

    • kankele's avatar
      kankele
      Occasional Contributor

      I'm using v8 on win7 x64. Sometime in the next week or so we should have v10 online and I can check it there.