zo- Respected Contributor.
Respected Contributor.
165 views

workflow scripting -- cannot check for null values?

Does anyone know how to check for null values in workflow scripting? Every method I've tried has failed -- as far as I can tell, my nullchecks just get passed automatically because the script cannot see the contents of the database cell.

The core issue is that you cannot see the contents of a field without performing a query, and performing a query on a null value crashes your script... so you cannot find out if the value is null without crashing in the process.

 

I've tried every variety of nullcheck I'm aware of, I've even strung them together as a series of If's, and it just blasts through them regardless and then crashes if the script runs on a blank field. Actually, to be more accurate, it is crashing on the second nullcheck -- the minute you try to check for "", it runs a query, and if it is blank, it crashes. Obviously, the intended function here would be to skip the test if the value is blank, but, the whole script crashes instead. vbNull appears to do nothing. The band-aid fix is to make the relevant field a required field, but, there are downsides with that specific to our workflow.

Here's my (unsuccessful) attempts to check for null values:

If (reqRefInput <> vbNull) Then					'this parsing is#
	'MsgBox "vbNull passed",0,"debug"		'><><><DEBUG
	If (reqRefInput <> " ") Then				'#a major work#
		'MsgBox "'' passed",0,"debug"		'><><><DEBUG
		If (reqRefInput <> "") Then			'#in progress
			'MsgBox "' ' passed",0,"debug"	'><><><DEBUG

For reference, earlier in the code, reqRefInput is defined as:

reqRefInput = TestCase.Field(testField)

....and, testField is defined, in this particular domain, as

testField = "TS_USER_07" 

 

Nothing I've tried defeats the null crash, aside from making the field required and replacing blanks with "xx" when I find them. This is more difficult with my latest experimental feature, which utilizes a memo field instead of a regular field to get around the 255 charlimit... as memo fields unfortunately cannot be filtered on, in the Test Plan grid view. I can mark them required too, but it will confuse a few workstreams, and it doesn't help me remove the existing blank values on thousands of tests.

 

Does anyone know anything useful here? Thanks!
~Z

0 Likes
4 Replies
Knowledge Partner
Knowledge Partner

Re: workflow scripting -- cannot check for null values?

You are in workflow script and it means you have to use VBScript.

If you want to get information about object "TestCase.Field(testField)" then I recommend to use these functions to get the info:

IsObject(TestCase.Field(testField))

VarType(TestCase.Field(testField))

TypeName(TestCase.Field(testField))

isEmpty(TestCase.Field(testField))

IsNull(TestCase.Field(testField))

 

I think it will give you the information that you need to understand what the objects is for and what contains. See the VBScript help:

https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp

0 Likes
zo- Respected Contributor.
Respected Contributor.

Re: workflow scripting -- cannot check for null values?

I'm aware. Neither vbNull or isNull actually work -- it just goes past the check as if the value is not null. Feel free to check for yourself.

0 Likes
Knowledge Partner
Knowledge Partner

Re: workflow scripting -- cannot check for null values?

See this part "TestCase.Field(testField)".

It depends what it is and how do you get it and from what.

What is th object "TestCase"

If it is the object get from TDConnection.TestFactory.Item(<testid>) like:

set TestCase = TDConnection.TestFactory.Item(21)

then it is standard VBScript OTA API object you can use TestCase.Field("TS_USER_07") for getting the value of variable of field "TS_USER_07". And how did you set this field in ALM client customization:

TestCase.png

It is the Look up list or String or Number or ...?

 

The second possibility is to get directly the value directly from workflow context objects like this:

Test_Fields.Field("TS_USER_07").Value

But you have to write this script in Test Plan Module Script and you want the actual value from current test.

 

Lastly what answer give you the first statements?:

IsObject(TestCase.Field(testField))

VarType(TestCase.Field(testField))

TypeName(TestCase.Field(testField))

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: workflow scripting -- cannot check for null values?

I have tried both possibility and it works fine:

I have setup button in test plan with action name: "TP1"

Here is the workflow script in Common:

---------------------------------------------

Function ActionCanExecute(ActionName)
  ' On Error Resume Next
  if ActionName = "TP1" then printfieldvalue
  ActionCanExecute = DefaultRes

  ' On Error GoTo 0
End Function

----------------------------------------------------

here is the Test Plan workflow script:

------------------------------------------------------

sub printfieldvalue
  msgbox "current test in workflow context " _
    & chr(13) & " field dbname: " & Test_Fields.Field("TS_USER_01").FieldName _
    & chr(13) & " fieldlabel: " & Test_Fields.Field("TS_USER_01").FieldLabel _
    & chr(13) & " field value: '" & Test_Fields.Field("TS_USER_01").Value & "'"
  if Test_Fields.Field("TS_USER_01").Value = "" then
    r = true
  else
    r = false
  end if
  msgbox " IsObject(Test_Fields.Field(""TS_USER_01"").Value): " & IsObject(Test_Fields.Field("TS_USER_01").Value) _
    & chr(13) & " VarType(Test_Fields.Field(""TS_USER_01"").Value): " & VarType(Test_Fields.Field("TS_USER_01").Value) _
    & chr(13) & " TypeName(Test_Fields.Field(""TS_USER_01"").Value): " & TypeName(Test_Fields.Field("TS_USER_01").Value) _
    & chr(13) & " IsNull(Test_Fields.Field(""TS_USER_01"").Value): " & IsNull(Test_Fields.Field("TS_USER_01").Value) _
    & chr(13) & " IsEmpty(Test_Fields.Field(""TS_USER_01"").Value): " & IsEmpty(Test_Fields.Field("TS_USER_01").Value) _
    & chr(13) & " Test_Fields.Field(""TS_USER_01"").Value = """": " & r

  set TestCase = TDConnection.TestFactory.Item(5)
  msgbox "any test from test plan get by TEST ID = 5: " & chr(13) & " field value: '" & TestCase.Field("TS_USER_01") & "'"
  if TestCase.Field("TS_USER_01") = "" then
    r = true
  else
    r = false
  end if
  msgbox " IsObject(TestCase.Field(""TS_USER_01"")): " & IsObject(TestCase.Field("TS_USER_01")) _
    & chr(13) & " VarType(TestCase.Field(""TS_USER_01"")): " & VarType(TestCase.Field("TS_USER_01")) _
    & chr(13) & " TypeName(TestCase.Field(""TS_USER_01"")): " & TypeName(TestCase.Field("TS_USER_01")) _
    & chr(13) & " IsNull(TestCase.Field(""TS_USER_01"")): " & IsNull(TestCase.Field("TS_USER_01")) _
    & chr(13) & " IsEmpty(TestCase.Field(""TS_USER_01"")): " &  IsEmpty(TestCase.Field("TS_USER_01")) _
    & chr(13) & " TestCase.Field(""TS_USER_01"") = """": " & r

  set tsfield = TDConnection.Fields("TEST")
  for i = 1 to tsfield.Count
    if tsfield.Item(i).Name = "TS_USER_01" then
      set objField = tsfield.Item(i)
      exit for
    end if
  next
  set objFieldProp = objField.Property
  msgbox "description of field from TDConnection.Fields(""TEST""):" _
    & chr(13) & " dbfield name: " & objField.Name _
    & chr(13) & " database type: " & objField.Type _
    & chr(13) & " UserLabel: " & objFieldProp.UserLabel _
    & chr(13) & " UserColumnType: " & objFieldProp.UserColumnType _
    & chr(13) & " DBTableName: " & objFieldProp.DBTableName _
    & chr(13) & " DBColumnType: " & objFieldProp.DBColumnType _
    & chr(13) & " DBColumnName: " & objFieldProp.DBColumnName
  end sub

------------------------------------------------------

Here is setting in customization:

TestCase1.png

Here is the answers for msgboxes:

TestCase2.png

 

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.