Forum Discussion

jw25's avatar
jw25
Occasional Contributor
3 years ago

invalid left-hand side in assignment when changing value of cell

 

Hello and welcome to my forum post. I'd love some help and guidance with my current issue. 

I get this error when running this test, basically what happens is that testcomplete doesn't want to change the value of the cell. In the test it takes a property of the web application. This beeing an article nummer. For example artikelnummer: IN12345. Then using the aqstring.Remove function, it removes the string part of this article nummer. So what is left is just the nummer (ie. 12345). This can then be used to compare to the article nummer in earlier instances. This worked fine when I wasn't using a table to store the article nummers. The reason I am now is because this seems like a practical solution for when theres multiple article numbers involed. (Whenever more than 1 item has been added to the checkout).

function TrimArtNum (ChkArtNumTrim){
  Log.Message(ChkArtNumTrim); 
  var counter = Project.Variables.Counter;
  //Project.Variables.ArtNumChkT.$set("Item", 0, 0, ChkArtNumTrim);
  Project.Variables.ArtNumChkT.Item(0, counter) = aqString.Remove(ChkArtNumTrim,0,15);
  Log.Message(Project.Variables.ArtNumChkT.Item(0, counter)); 
}

^The code where I get the error. Now I did some checking myself and from what I see on https://community.smartbear.com/t5/TestComplete-Questions/JavaScript-quot-ReferenceError-Invalid-left-hand-side-in/m-p/196706#M5376 and on https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript.html#indexed-properties.

The set variable function is required. I've tried messing around with that function but I don't seem to get it working. 

 

Heres the keyword test that calls and uses the script.

 

Any help is apreciated.

 

    • jw25's avatar
      jw25
      Occasional Contributor

      Not entirely sure which variable you are referring too. Theres three variables in this problem. The ArtNumChkT is a table variable. The counter variable, which is an integer. It's simply there to help me go trough the table. Lastly the ChkTrimArtNum is a parameter in the script function. I haven't seen any options to specify that the table or the parameter should be a string so I assume TestComplete figures that out itself. 

      In the Debug mode I can see that it takes and uses the value in the parameter so that should be fine. However the aqString object might not work if it does not consider it a string.

    • jw25's avatar
      jw25
      Occasional Contributor

      So I made some progress, or so i think. 

      function TrimArtNum (ChkArtNumTrim){
        Log.Message(ChkArtNumTrim); 
        var counter = Project.Variables.Counter;
        var ArtNum = Project.Variables.ArtNumChkT.Item(0, counter);
        ArtNum = aqConvert.VarToStr(ChkArtNumTrim);
        ArtNum = aqString.Remove(ChkArtNumTrim,0,15);
        Log.Message("test " + ArtNum);
        
        Project.Variables.ArtNumChkT.$set(" Project.Variables.ArtNumChkT", 0, 0, ArtNum);
        
      }

       I added a second variable (ArtNum). Artnum goes trough the code properly. What still remains though is saving this value to the cell. I figured this is where i'd use the set method I've been reading about. However, now I get another error: 

      Error: The object does not support this property or method. It referring to the %set line.