Identical queries but one doesn't return records

Hello, I have this script:

	    		
	# CHECKING IF SHEET TEXTBOX IS FILLED OUT
	elif self.getSibling("TextField_Sheet").props.text is not None and len( self.getSibling("TextField_Sheet").props.text) >2: 	    
			txt = "%" +  self.getSibling("TextField_Sheet").props.text + "%" # CREATING LIKE PARAMETER %userinput%
			self.custom.custpro = txt # WE HAVE A CUSTOM PROPERTY ON THE BUTTON, IT'S A PARAMATER THAT'S BOUND TO THE TABLE			
		 	query = "SELECT COUNT(*) FROM ProductionData.dbo.DrawingInfo WHERE Val2 LIKE ? AND DocType = 2"				      
		  	results = system.db.runPrepQuery(query, [txt]) # RUNNING QUERY	
		  	rCount = results.getValueAt(0,0)
			self.getSibling("Label_Just_Doc_Found").props.text = "Documents Found: " + str(rCount) # UPDATING THE NUMBER OF DOCUMENTS FOUND    
		    
		    # HIDING TABLES EXCEPT FOR SHEET TABLE_1
			self.getSibling("Default_Table").meta.visible = False    
			self.getSibling("Table_0").meta.visible = False		    
			self.getSibling("Table_1").meta.visible = True		   
		   	self.getSibling("Table_2").meta.visible = False 

There are several textboxes and this query will run and return records if there are any - this is tied to a button. The next script is tied to a textbox and will run if the user presses enter.
Here is the script:

    # RUNNING SEARCH SCRIPT WHEN ENTER IS PRESSED
	if event.charCode == 13:
		
		# CHECKING IF ASSET TEXTBOX IS FILLED OUT
		if self.getSibling("TextField_Sheet").props.text is not None and len(self.getSibling("TextField_Sheet").props.text) > 2:  					
			txt = "%" +  self.getSibling("TextField_Sheet").props.text + "%" # CREATING LIKE PARAMETER %userinput%
			self.custom.custpro = txt # WE HAVE A CUSTOM PROPERTY ON THE BUTTON, IT'S A PARAMATER THAT'S BOUND TO THE TABLE			
		 	query = "SELECT COUNT(*) FROM ProductionData.dbo.DrawingInfo WHERE Val2 LIKE ? AND DocType = 2"				      
		  	results = system.db.runPrepQuery(query, [txt]) # RUNNING QUERY	
		  	rCount = results.getValueAt(0,0)
			self.getSibling("Label_Just_Doc_Found").props.text = "Documents Found: " + str(rCount) # UPDATING THE NUMBER OF DOCUMENTS FOUND    	    
		    
		    # HIDING TABLES EXCEPT FOR ASSET TABLE_0
			self.getSibling("Default_Table").meta.visible = False
			self.getSibling("Table_0").meta.visible = True    
			self.getSibling("Table_1").meta.visible = False    
			self.getSibling("Table_2").meta.visible = False    
		  	system.perspective.print(txt)  
			# IF 0 RECORDS ARE RETURNED, WE POPULATE THE TABLE WITH 0 DATA

What is wrong? Why will the same query run when a button is clicked, but when run off of the textbox it wont. I've tried everything... I used the console to verify that the script is hitting the if statement and traversing down it. I copied the code to sql and ran it, works fine- They're identical.

You are relying on .getSibling(). That only works when the component catching the event actually is the sibling of the various fields.

Consider using view custom properties to hold all of your entries (bidirectionally bound from the fields), so you can use self.view.custom.someFieldValue, which will work for any component or event within the view.

3 Likes