101101
102102
103103class ServiceNowListTask (AbstractServiceNowTask ):
104+ OPERATOR_EQUALS = "="
105+ OPERATOR_NOT_EQUALS = "!="
106+ OPERATOR_STARTSWITH = "STARTSWITH"
107+ OPERATOR_ISEMPTY = "ISEMPTY"
108+ OPERATOR_EMPTYSTRING = "EMPTYSTRING"
104109
105110 @classmethod
106111 def all_configs (cls ) -> List [dict ]:
@@ -777,6 +782,9 @@ def validate(
777782 list_info = self ._extract_list_info (page )
778783 current_query = list_info ["query" ]
779784
785+ if not current_query :
786+ return 0 , False , "" , {"message" : "There are no filters yet." }
787+
780788 # Replace "new query" statements with the standard OR separator
781789 current_query = current_query .replace ("^NQ" , "^OR" )
782790
@@ -789,24 +797,44 @@ def validate(
789797 current_sep = "^"
790798
791799 if current_kind != self .filter_kind :
792- return 0 , False , "" , {"message" : "The kind of filter used is incorrect." }
800+ return 0 , False , "" , {"message" : f "The kind of filter used is incorrect: { current_query } ." }
793801
794802 # Extract the query pieces for validation
795803 current_query = current_query .split (current_sep )
796804
797805 # Validate query length is ok
798806 if len (current_query ) != self .filter_len :
799- return 0 , False , "" , {"message" : "Incorrect number of filter conditions." }
807+ return 0 , False , "" , {"message" : f"Incorrect number of filter conditions: { current_query } ." }
808+
809+ # Parse column names, operators, and values
810+ current_columns , current_operators , current_values = [], [], []
811+
812+ # Note that this is not exhaustive. If/when other operators are added, this will have to be updated.
813+ for predicate in current_query :
814+ if self .OPERATOR_EMPTYSTRING in predicate :
815+ current_columns .append (predicate .replace (self .OPERATOR_EMPTYSTRING , "" ).strip ())
816+ current_operators .append ("=" )
817+ current_values .append ("" )
818+ elif self .OPERATOR_ISEMPTY in predicate :
819+ current_columns .append (predicate .replace (self .OPERATOR_ISEMPTY , "" ).strip ())
820+ current_operators .append ("=" )
821+ current_values .append ("" )
822+ elif any (unsupported_operator in predicate for unsupported_operator in [self .OPERATOR_NOT_EQUALS , self .OPERATOR_STARTSWITH ]):
823+ return 0 , False , "" , {"message" : f"Unexpected operator in filter condition: { current_query } ." }
824+ elif self .OPERATOR_EQUALS in predicate :
825+ col , val = predicate .split (self .OPERATOR_EQUALS , 1 )
826+ current_columns .append (col .strip ())
827+ current_operators .append ("=" )
828+ current_values .append (val .strip ())
829+ else :
830+ return 0 , False , "" , {"message" : f"Unexpected operator in filter condition: { current_query } ." }
800831
801- # Validate query columns are ok
802- current_columns = [x .split ("=" )[0 ] for x in current_query ]
803832 if set (current_columns ) != set (self .filter_columns ):
804- return 0 , False , "" , {"message" : "Incorrect filter columns." }
833+ return 0 , False , "" , {"message" : f "Incorrect filter columns: { set ( current_columns ) } . Expected: { set ( self . filter_columns ) } ." }
805834
806835 # Validate query values are ok
807836 # This is the tricky part because we need to expand the values to their display values
808837 # We also need to handle the case where the value is a reference
809- current_values = [x .split ("=" )[1 ] for x in current_query ]
810838
811839 # Handle filtering across multiple rows
812840 if len (set (current_columns )) < len (current_columns ):
@@ -856,9 +884,9 @@ def validate(
856884
857885 # Validate the values
858886 if set (current_values ) != set (self .filter_values ):
859- return 0 , False , "" , {"message" : "Incorrect filter values." }
887+ return 0 , False , "" , {"message" : f "Incorrect filter values { set ( current_values ) } . Expected: { set ( self . filter_values ) } ." }
860888
861- return 1 , True , "Nice work, thank you!" , {"message" : "Correct filter." }
889+ return 1 , True , "Nice work, thank you!" , {"message" : f "Correct filter: { list_info [ "query" ] } ." }
862890
863891
864892class ExtractListInfoTask (ServiceNowListTask ):
0 commit comments