Why does my "matches" wildcard criteria work on a BAQ, but not in a quick search?

@ckrusen you are awesome.

2 Likes

A couple of caveats … If the the search has multiple criteria, and the one you want to break up into individual criteria isn’t the last one, the other original criteria fields would get “overwritten” (actually you’d be in the condition where multiple rows with the same Seq value exist.

Criteria1: Red White Blue
Criteria2: 7/4/2021

Just adding extra criteria rows would give you:

SEQ  FieldName        CriteriaValue
1    PartDescription  "Red White Blue"
2    EndDate          7/4/2021
1    PartDescription  "Red"
2    PartDescription  "White"
3    PartDescription  "Blue"

I think you’d lose the filtering affect of Criteria2 for the End Date

I’m tracking with you. I cleared my original Part Description value so it’s essentially searching with no criteria. I did find that Seq value issue also so I start at 99 and I subtract i from it. It’s working now. Also, I tried to put a condition widget ahead of my Custom Code block, and I can’t seem to get that to work for anything. I was trying to get it to only fire if it recognized the QuickSearchID… but it somehow makes my results only consider the final search term. I fiddled with it for awhile but I eventually decided that it wouldn’t be the worst thing in the world if it fired every time someone searched a quick search on Part Description.

Can you put the check of the QuickSerach ID in the Custom Code widget? Basically wrap your custom code in a if statement?

Yep. Good call. Here’s my final code. Seems to only be triggered using my Part Quick Search and it now handles multiple search terms in any order. If anyone has any other suggestions, let me know. Otherwise, it seems to be working perfectly. Thanks, Calvin!

string getSearchValue = (from s in ttQuickSearchCriteria
                      where s.FieldName == "PartDescription"
                      && s.QuickSearchID == "Part_00"
                      select s.CriteriaValue).FirstOrDefault();

if (getSearchValue != null)
{
  var searchTerms = getSearchValue.Split(' '); // SPLIT THE SEARCH VALUE INTO MULTIPLE VALUES
  
  if (searchTerms.Length > 1) // ONLY USE THIS MODIFICATION IS THERE IS MORE THAN 1 WORD IN THE SEARCH
  {
    var modifyQuickSearchCriteria = (from s in ttQuickSearchCriteria
                                     where s.FieldName == "PartDescription"
                                     select s).FirstOrDefault();
    modifyQuickSearchCriteria.CriteriaValue = "";
    
    string Company = "VANAIR";
    string QuickSearchID = "Part_00";
    string GlbCompany = "";
    int Seq = 999;
    string DataTableID = "Part";
    string FieldName = "PartDescription";
    string DataType = "nvarchar";
    string FieldLabel = "Description";
    string CompOp = "MATCHES";
    string CriteriaType = "Prompt";
    bool IsReturnCol = false;
    string CriteriaValue = "";
    bool FilterOnNull = true;
    bool SystemFlag = false;
    string CriteriaField = "Part_PartDescription";
    string CriteriaLikeFieldName = "PartDescription";
    string CriteriaLikeTableID = "Part";
    string FieldFormat = "x(1000)";
    string LikeField = "Part.PartDescription";
    int BitFlag = 0;
    
    for (int i = 0; i < searchTerms.Length; i++)
    {
      CriteriaValue = searchTerms[i];
      
      var row = ttQuickSearchCriteria.NewRow();
      row["Company"] = Company;
      row["QuickSearchID"] = QuickSearchID;
      row["GlbCompany"] = GlbCompany;
      row["Seq"] = Seq + i;
      row["DataTableID"] = DataTableID;
      row["FieldName"] = FieldName;
      row["DataType"] = DataType;
      row["FieldLabel"] = FieldLabel;
      row["CompOp"] = CompOp;
      row["CriteriaType"] = CriteriaType;
      row["IsReturnCol"] = IsReturnCol;
      row["CriteriaValue"] = CriteriaValue;
      row["FilterOnNull"] = FilterOnNull;
      row["SystemFlag"] = SystemFlag;
      row["CriteriaField"] = CriteriaField;
      row["CriteriaLikeFieldName"] = CriteriaLikeFieldName;
      row["CriteriaLikeTableID"] = CriteriaLikeTableID;
      row["FieldFormat"] = FieldFormat;
      row["LikeField"] = LikeField;
      row["BitFlag"] = BitFlag;
      
      ttQuickSearchCriteria.Add(row);
    }
  }
}

Would you be able to attach this BPM? That would be greatly appreciated