App Studio: Event trigger for search field when value is manually entered

Hopefully this is an easy one.

Creating a dashboard which includes a customer search. Done, works. No issue.

I also want the user to be able to type in a CustID (instead of requiring the search). I can do this with an on-blur event… works. BUT… this field is in focus when the screen loads. If I click off of it, I get an error/prompt because my on-blur event fires before a value is defined.

How does one allow for a user-entered value in a search field? Perhaps the on-blur is the way to go, but I need a condition to check for undefined values?

Can you add a condition at the beginning of your onBlur event that checks for empty ('') or null ('undefined')? … if false, then do the rest of your actions

That field should have a binding so you should be able to use the field updated event instead of on blur

Much like classic drive events off data not controls

5 Likes

Are your Advanced selections for Drop Down Style = DropDown and Allow Custom = false?

Not a drop down… just a text field.

image

1 Like

Sorry, that took me a while to test. I got it set up and things were going crazy… ended up wiping out my whole dashboard and rebuilding… now works like a charm. Must’ve gotten corrupted somewhere along the line.

Appreciate the quick help!

2 Likes

Hi there, just wondering if you could share some screen shots of the Event? I’m trying to do something similar with Employee ID when a user enters the EmpID and then tabs out of field. Thanks!

Sorry, took me a bit to remember what Dashboard I was working on at the time. :rofl:

So, a little background on this one so what you’ll see below makes more sense… The dashboard I was creating was just sales activity against Customer accounts. So, the user would search for the CustID (or enter it manually) and it would trigger two different BAQ’s to run. One returned historical quotes for that customer, the other would return sales orders.

Our account activity often gets “muddy”. We have Account Managers, and also Account Associates (junior sales persons if you will). So, these BAQs would break the Sales Order salesreplist into independent columns (SalesRep1, SalesRep2, SalesRep3, etc.). It would also list sales persons on the quotes from QuoteReps to SalesRep1, SalesRep2, etc.

After running the BAQ’s I could then filter the BAQ grids for a specific sales rep and see only the records they were involved with (thus getting a slightly better idea of how much activity they were actually participating in for a specific customer account). And also filter the grids by date so we could see how active a specific sales person has been with a specific account over a specific time period.

Anyway… not overly important…

I had a Customer search… just a textbox
image

I bound that to KeyFields.CustID:
image

I also set “Enable Search” to true under Advanced.

I had one set of events firing based on the “On Search Click” behavior which drove the primary Customer Search.

For when they were typing it in (this is the part you’re interested in)… I had the below event:

image

So, with the textbox bound to KeyFields.CustID, the trigger picks up any time that value changes:
image

The condition makes sure the CustID is not blank or ‘undefined’
'{KeyFields.CustID}' === '' || '{KeyFields.CustID}' === 'undefined'

If that returns false, it goes to event next… which was my Customer Rest call using GetByCustID (based on the user’s CustID input value):
image

After that, it went into another event-next “nfm_onchange_CustID”. This one simply re-ran the two BAQ’s discussed above to pull back updated records based on the new CustID value.
image

The other thing to keep in mind… since this was a new dashboard built from scratch… if you remember, I had bound my CustID field to KeyFields.CustID. Well, the KeyFields dataview didn’t exist in a fresh dashboard… so if you do something like that, remember you have to manually create the KeyFields DataView.

Nothing in it… just create it:

You also have to initiate it when the form loads via event(s).
image

As you can see I was initiating both KeyFields and TransView dataviews. So, after the window loads, this event fires, which runs two other events. These just include a row update:

image

In the row update… I just set my KeyField to an empty value: “”
But that’s enough to initialize the dataview so I can use it in my dashboard.

image

Clear as mud?

Morgan Freeman Good Luck GIF

4 Likes

Thanks so much for taking the time to explain that in detail :slight_smile: I’ll be picking up what I was working on next Monday so will let you know how I get on then!

I finally had a chance to loop back to this customisation! My events ended up being slightly different, but your explanation definitely set me on the right path.

Write up below of what I implemented :slight_smile:

In Corrective Action we have the following UD fields which link to EmpBasic table:
DMRCorAct.Inspector_c (EmpBasic.EmpID)
DMRCorAct.InspectorName_c (EmpBasic.Name)
DMRCorAct.InspectorFirstName_c (EmpBasic.FirstName)
DMRCorAct.InspectorLastName_c (EmpBasic.LastName)

DMRCorAct.Inspector_c is enabled as a search field, but I needed Name, First Name and Last Name fields to be populated/updated when:

  • Inspector_c (EmpID) is populated via search icon
  • Inspector_c (EmpID) is typed into field

Event 1: On Click event for search icon (pretty simple). Returns value for all 4 fields.

Event 2: When Inspector ID is typed in this Event updates the Name. For this one I was able to copy an out of the box event for DMRCorAct.AuditBy. The rest service (CorrectiveAction.VerifyEmpId) already does the validation to check that the EmpID exists, but only contains parameters for EmpID and Name, so I couldn’t use this to update the FirstName and LastName fields as well.


imageimage
image

Value": “{actionResult.empName}”

I then created a Dataview for EmpBasic table called “EmpBasic_c” to use with my last event.

image

Event 3: When DMRCorAct.Inspector_c has changed this event checks if the field is null. If True it clears any values in InspectorFirstName_c and InspectorLastName_c fields. If False it does a rest call to EmpBasic.GetByID to populate my new Dataview (EmpBasic_c). It then does a row update to populate FirstName and LastName fields.


image
image
image
image
imageimage
imageimage

2 Likes