Escaping special characters in HP ALM filter conditions
If you have to apply filters in HP ALM programmatically the following function allows you to escape characters in filter strings, which cause runtime errors if not handled properly.
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
' @Author - Alexander Bolte' @ChangeDate - 2015-01-07' @Description - Adjusting a handed filter condition to comply with functional restrictions of ALM.' A filter condition must not contain ...' - spaces without embracing the whole condition with quotation marks.' - not escaped quotation marks.' - line breaks.' This function is cleaning a handed filter condition of the above listed errors.' @Param cond - A String providing a filter condition to be cleaned for usage in ALM.' @Returns - a cleaned filter condition as String.' In case of error an empty String is returned.PublicFunctioncheckCondition(cond)' As StringDimflt' As StringOnErrorResumeNext' Set the filter string which will be returned to temp variable in order to' avoid possible errors caused by handing a variable by reference and not' by value.flt=condflt=Trim(flt)' Escape special character quotation mark.flt=Replace(flt,"""","\""")' Embrace condition with quotation marks in case a condition contains spaces.IfInStr(1,flt," ")>0Thenflt=""""&flt&""""EndIf' Remove line breaks from filter condition.flt=Replace(flt,vbCr,"")flt=Replace(flt,vbLf,"")IfErr.Number<>0ThenErr.Clearflt=""EndIfcheckCondition=fltEndFunction