Find a total number of Parts that fit a condition [Epicor Customization Tools - Script Editor for Parts Table]

Hii, I’m new to Epicor and was hoping that I will be able to receive some help on the following issue.

I am trying to use Customization tools on the Part Display page. I added a button. When one clicks on this button, the code should display the “next open serial number”.

Note that some part numbers may just be a sequence of digits, some will have letters, special characters etc). I am specifically looking for ones that start with “HQT” and are followed by 6 digits.

With that being said, I want to first find all Part Numbers start with “HQT” and are followed by 6 digits. I want to find the highest 6 digits that follow “HQT” so that I can increment it by 1 and suggest the next open serial number.

This is my C# code for that part… If I press my button, I will get “Not Responding” error
image

	private void epiButtonC5_Click(object sender, System.EventArgs args)
	{
	    string whereClause = "PartNum LIKE 'HQT[0-9][0-9][0-9][0-9][0-9][0-9]' ";
	    
	    // Create a hashtable to store search conditions
	    System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
	    whereClauses.Add("Part", whereClause);
	    
	    // Create SearchOptions with the whereClauses hashtable
	    SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
	    
	    // Invoke search with the constructed search options
	    this._partAdapter.InvokeSearch(searchOptions);
	
	    // Retrieve the part data
	    DataTable partTable = this._partAdapter.PartData.Part;
	
	    // Check and display the number of rows found
	    if (partTable == null)
	    {
	        MessageBox.Show("partTable is null");
	    }
	    else
	    {
	        int rowCount = partTable.Rows.Count;
	        MessageBox.Show("partTable contains " + rowCount.ToString() + " rows.");
	    }
	}

However, if I tried testing with a part that I know exists, it will give back the correct value which is “partTable contains 1 rows”.

	private void epiButtonC5_Click(object sender, System.EventArgs args)
	{
	    string knownPartNum = "something here"; // a known valid part number.
	    
	    // Create a hashtable to store search conditions
	    System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
	    string whereClause = "PartNum = '" + knownPartNum + "'";
	    whereClauses.Add("Part", whereClause);
	    
	    // Create SearchOptions with the whereClauses hashtable
	    SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
	    
	    // Invoke search with the constructed search options
	    this._partAdapter.InvokeSearch(searchOptions);
	
	    // Retrieve the part data
	    DataTable partTable = this._partAdapter.PartData.Part;
	
	    // Check and display the number of rows found
	    if (partTable == null)
	    {
	        MessageBox.Show("partTable is null");
	    }
	    else
	    {
	        int rowCount = partTable.Rows.Count;
	        MessageBox.Show("partTable contains " + rowCount.ToString() + " rows.");
	    }
	}

If anyone found a mistake or could give any advice/insight into my situation. I would really appreciate the help!

Thank you