I trying to find the syntax where I can use Not keyword with String.Contains condition in UIPath.
Example for : I have following variable.
strValue = “This is Test”
I want to check whether 'Test' word is not existed in the variable then it should show me some message.
I have tried below approach but it did not work.
Not strValue.Contains(“Test”)
you can use indexOf(). It will return -1 if value to search is not present in string.
strValue = “This is Test”
var i = strValue.indexOf("Test");
if(i>0){
console.log('Test is present in strValue');
}
Related
I know that with Descriptive programming you can do something like this:
Browser("StackOverflow").Page("StackOverflow").Link("text:=Go To Next Page ", "html tag:=A").Click
But is it possible to create some kind of string so I can assign more than one data value and pass it as single variable? I've tried many combinations using escape characters and I always get error.
For example in the case above, let's say I have more properties in the Page object, so I'd normally have to do something like this:
Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")...etc...
But I'd like to pass "name:=StackOverflow", "html id:=PageID" as a single variable, so when writing many objects I'd only have to write:
Browser(BrowserString).Page(PageString).WebEdit("name:=asdfgh")
And the first part would remain static, so if the parents' data needs to be modified I'd only have to modify two variables and not all the objects created in all libraries.
Is it possible?
If I was not clear enough please let me know.
Thank you in advance!
I think what you're looking for is UFT's Description object
This allows you finer grained control on the description since in descriptive programming all values are regular expressions but with Description you can turn the regular expression functionality off for a specific property.
Set desc = Description.Create()
desc("html tag").Value = "A"
desc("innertext").Value = "More information..."
desc("innertext").RegularExpression = False
Browser("Example Domain").Navigate "www.example.com"
Browser("Example Domain").Page("Example Domain").WebElement(desc).Click
If you want to represent this with plain string then it's a bit more of a problem, you can write a helper function but I'm not sure I would recommend it.
Function Desc(descString)
Set ret = Description.Create()
values = Split(descString, "::")
For Each value In values
keyVal = Split(value, ":=")
ret(keyVal(0)).Value = keyVal(1)
Next
Set Desc = ret
End Function
' Usage
Browser("StackOverflow").Page("StackOverflow").WebElement(Desc("html tag:=H2::innertext:=some text")).Click
Further reading about descriptive programming.
As an alternative to Motti's excellent answer, you could also Set a variable to match your initial descriptive object and then extend it as required:
Set myPage = Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")
after which you can then use
myPage.WebEdit("name:=asdfgh")
throughout the rest of the code, so long as the myPage object stays in scope...
I am working on small VBScript and trying to create scripting.dictionary[]. I have to pass that array of dictionary to a function by ref. I got that function through compiled library. the function definition is below.
public string Update(string name, ref Scripting.Dictionary[] Data, string sRecordId = "")
My lines of code is here
Set objQWS = CreateObject("Dll")
Set X = PassDictionary
objQWS.Update "Name", x, ""
MsgBox "Additional Info Sent"
Function PassDictionary()
Dim objDic
Set objDic = CreateObject("Scripting.Dictionary")
objDic.Add "id", 1
objDic.Add "name", "a"
objDic.Add "extd_price", "b"
objDic.Add "sales_rep", "c"
objDic.Add "opportunity_id", "d"
Set PassDictionary = objDic
End Function
The problematic area is the Update function.
Every time I run the code, on Update function it give me the error "type mismatch". can anybody tell me how can I make that thing working?
You're passing a single dictionary, not an array of dictionaries. Try something like
Set x = PassDictionary
arr = Array(x)
objQWS.Update "Name", arr, ""
Not sure if it'll work, though, since VBScript doesn't really know types, so the array will have the type Variant().
Another thing you could try is to change the type of the parameter from Scripting.Dictionary[] to Scripting.Dictionary, since you're only passing a single dictionary anyway.
I'm trying to do the following update using XPages Extension Library.
#{javascript:var mydata = {
product: getComponent("inputProduct").getValue()
};
var params = [1, 2];,
#JdbcUpdate("mssql","table_name",mydata,"order_no=? AND order_line_no=?",params)};
I get the error:
Error while executing JavaScript action expression
Script interpreter error, line=6, col=1: Error while executing function '#JdbcUpdate'
Invalid column name 'PRODUCT'.
The problem is that XPages when it converts the JSON it puts product to PRODUCT.
Can you set the extension library to respect the case of the JSON and not convert to Uppercase? Or can anyone point to where this setting could be set if not the extension library?
Thanks
The problem is com.ibm.xsp.extlib.util.JdbcUtil.appendColumnName()
public static void appendColumnName(StringBuilder b, String colName) {
colName = colName.toUpperCase();
b.append(colName);
}
This just needs changing to not upper case the variable.
There may be other methods that need changing if other variables are getting upper cased.
I am trying to check if the 'Listivew.Tag property is nothing'.
I used to do the 'Is Nothing' check universally for all scenarios as first check to avoid errors
Can someone explain how to do it in VB 6?
If Not .lvwLocation.Tag Is Nothing Then
'COMPANY
str = str & IIf(Len(.lvwLocation.Tag) > 0, " and u.location_id in " & .lvwLocation.Tag, "")
End If
Gives error 'type-mismatch'
Nothing is a valid value for Object variables, and Is is the way to compare object pointers.
But a VB6 control's Tag property is a String, and VB6's String type is not an Object; it's a primitive type. That means a String variable can't be assigned Nothing -- its emptiest possible value is the empty string. (And an Object variable can't be assigned a String value.) For strings just use the same equality/inequality/comparision operators that you use for other primitive (numeric/boolean/date) types:
If .lvwLocation.Tag <> "" Then ...
In VB6 it appears that using Is Nothing to compare Objects works, Every other data type that I tried did not. In .Net Nothing represents the default value of any data type and will work like you expect.
Dim test as Object
If Not test Is Nothing Then
/////
End If
Since it appears the data type of th Tag property in VB6 is a string. I would use something like:
If .lvwLocation.Tag <> "" Then
/////
End If
How can you check if a string is a valid GUID in vbscript? Has anyone written an IsGuid method?
This function is working in classic ASP:
Function isGUID(byval strGUID)
if isnull(strGUID) then
isGUID = false
exit function
end if
dim regEx
set regEx = New RegExp
regEx.Pattern = "^({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?$"
isGUID = regEx.Test(strGUID)
set RegEx = nothing
End Function
This is similar to the same question in c#. Here is the regex you will need...
^[A-Fa-f0-9]{32}$|^({|()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|))?$|^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$
But that is just for starters. You will also have to verify that the various parts such as the date/time are within acceptable ranges. To get an idea of just how complex it is to test for a valid GUID, look at the source code for one of the Guid constructors.
In VBScript you can use the RegExp object to match the string using regular expressions.
Techek's function did not work for me in classic ASP (vbScript). It always returned True for some odd reason. With a few minor changes it did work. See below
Function isGUID(byval strGUID)
if isnull(strGUID) then
isGUID = false
exit function
end if
dim regEx
set regEx = New RegExp
regEx.Pattern = "{[0-9A-Fa-f-]+}"
isGUID = regEx.Test(strGUID)
set RegEx = nothing
End Function
there is another solution:
try
{
Guid g = new Guid(stringGuid);
safeUseGuid(stringGuid); //this statement will execute only if guid is correct
}catch(Exception){}