Forum Discussion

bdrummond's avatar
bdrummond
Contributor
7 years ago

Object.Save() type-mismatch error - cannot save a property to TC Objects

 was wondering if TC cannot store a property of an object as Test Complete Object?   I have tried to save an object, but more precisely, trying to save the wText property of a title box as an objec...
  • tristaanogre's avatar
    7 years ago

    What does the following code actually return

     

    impUnit.getObject()

    As per the following, the first parameter of Objects.Save needs to be an onscreen object/component identified by TestComplete.  Second parameter needs to be a string to be used to save the Object in the stores.  It is a required field so, if you are missing the name string, it won't work.  Also, it needs to not contain spaces or special characters.  For property names to save, this is a space delimited list of properties.

     

    So... generally speaking, you aren't using Objects.Save properly...  1) you might not actually be passing in the proper object, depends upon that above code. 2) You are apparently missing the parameter to indicate the name to use for saving the object. and 3) if you want to store the wText property, your propertyNames variable should simply be "wText".  This will store that property and it's value.

     

    So... based upon what I'm seeing, I'd change the code to the following (see bolded line).  This will store the title box object into the stores area with the wText property set to whatever the current value is.  


     

    //Script unit to replace exising chart title to be saved.
    //
    
    //import unit uniqueID
    var impUnit = require("uniqueId");
    
    function chartTitle(){
      var ic = Aliases.IC;
      var getTitleBox = ic.saveChartAsForm.titleTxtBox;
      var x = impUnit.getObject(); //Retrieve the result of function uniqueId() from other unit.
      
      //set random number onto the title
      getTitleBox.SetText(x);  
      Log.Message("This is the randomly generated chart name: " + x);
        
      //Get the String object under title txt box
      var a = getTitleBox.wText; //----> this wont work...(?)<----
      var x = a;  
      Log.Message(x);
      
      //Prepares the property name
      propertyNames = "Generated Chart ID";
    
      //Save object into Objects in TestComplete
      Objects.Save(getTitleBox, "TitleBox", "wText");
      
    }