Skip to Content
0

Search a String for a variable

Nov 24, 2016 at 10:11 PM

64

avatar image

Hello Experts,

I am attempting to look at a user status field and find a string to use as a variable in an if statement. I am using the following code but am getting an error stating the includes method isn't recognized.

var string = session.findById("wnd[0]/usr/subSCREEN_1:SAPLIQS0:1050/txtRIWO00-ASTXT").text ;
subString = "APPR"
output = string.includes(subString);
session.utils.log (ouput) ;

Any advice on how to accomplish this would be greatly appreciated. We are looking to hide buttons depending on user status.

Thanks,

Andrew McGrath

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Tamas Hoznek
Nov 24, 2016 at 10:50 PM
0

Well, assuming that the last line has a typo with ouput and your script contains output instead, the problem is that the session.utils.log method only accepts strings. So in this case, you could use something like

output = ""+string.includes(subString);

and this will result in the string true or false being written into the log.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thanks for the quick reply Tamas. I am receiving the following error after changing the code as you stated.

Error during script execution:Object doesn't support property or method 'includes'TypeError: Object doesn't support property or method 'includes'
at Function code (Function code:4:3)
at self.executeScriptInternal (http://confidential.ca:1085/sap/bc/personas3/core/script/sap/personas/fw/its/scripting/ScriptingEngine.js?20160627170730:58:8895)
at sap.personas.scripting.executeScriptInternal (http://confiddential.ca:1085/sap/bc/personas3/core/script/sap/personas/fw/its/scripting/ScriptingEngine.js?20160627170730:58:11393)
at Anonymous function (eval code:1:594)

Is this method not available at my browser level possible?
0

The following script works fine for me and results in true:

var string = "S_APPR_WHATEVER" ;
subString = "APPR";
output = ""+string.includes(subString);
session.utils.log(output);

What you need should work well with if... something like

if (string.includes(subString)) { ... }

0