For #1
This is a little trickier than you might think, and is a little dependant upon how the data is being loaded into the form (adding rows to a table, populating a single-line field with one value, populating a single-line field with multiple values, populating a drop-down field with multiple values, etc.) You can build events in Javascript that run when the lookup is complete, like this:
$(document).on('lookupcomplete', function (event) {
if(event.triggerId == 'Field1')
{
console.log('lookup complete - Field1 was changed by user and triggered the lookup to occur.');
}
});
But that's where it can be a little tricky. You could have Javascript check if the other field that should be populated is blank to determine if the lookup failed - but that's if it was a single-line field that only ever produces 1 result. If there are multiple results, they'll show as suggested values. A drop-down will show as select elements in the field. Rows added to a table could be several other things.
One solution I've played with before is to have two different lookups. One of them populates the actual values I want to show from the Table or View, and the other uses a Stored Procedure that returns a count of matching records - which populates into a hidden field. Then you can add errors based on the populated value of the hidden field. You could do this with Field Rules to hide/show an error message fairly easily. You could employ Javascript to do pop-up messages or custom validation code if you wanted as well.
For #2
The system can handle the various options with databases fairly well.
Say you have a lookup that a user enters their first name, and it looks up the last name from an employee database table.
If both values are Single-Line fields:
- You'll see the last name field auto-populate if they are the only employee with that first name.
- You'll see all the possible last names populate as suggested text if there are multiple employees with that first name.
Also, you can have multiple fields feed into the lookup.
Say you have a lookup that a user enters their first and last names, and it looks up their employee number from an employee database table.
Since there are multiple lookup fields, the system will automatically create an "Auto fill" button that the user can click after entering both values, and that will trigger the lookup.
Personally, I use Javascript to hide the "Auto fill" button from the user, and programatically click the button when any of the fields used in the lookup are changed (after also checking none are blank).