Hi all,
I have a form that has a field as PK called Task_name
I would like to have a method that executes onfocusLost checks the PK and make sure that users are not entering the duplicate PK in Task_name field and warn users that cannot insert duplicate key in field Task_name, then return back into the same record allowing users to correct the Task_name field.
I have the following method that does not function as I stated above:
var message = “”
if (task_name == autism_to_autism.task_name)
{
message += ‘Cannot insert duplicate key in object Task_name .Return to return to the form \n’;
var ALERT = plugins.dialogs.showInfoDialog( ‘Result’, message, ‘Return’ );
}
if (ALERT == ‘Return’)
{
return;
}
Thanks for any help.
Abrahim
Primary key fields do not allow duplicates by nature! If it’s really a primary key - then it should be IMPOSSIBLE to enter duplicate values.
WHY would you have your PK field EDITABLE in the first place???
Bob,
The solution that Im working on it will be used as the Project Management tool for one of the groups that Im working with.
The primary key field in ADHD table serves as the project Task_Name which should be unique and will be populated only by the project manager for the ADHD group.
My intend is to make sure that there is not any duplicated project TASK_NAME in ADHD table.
Thanks,
Abrahim
OK - so it’s really not the database primary key - right?
Here’s a way to ensure non duplicate values. On the onDataChange event of the field do something like this:
(THIS IS PSEUDO CODE ONLY, SINCE I DON’T KNOW YOUR SCHEMA):
//Get a dataset based on query
var maxReturnedRows = 1
var query = "select count(*) from myTable where lower(adhd) = '" + adhd.toLowerCase() + "'"
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturnedRows);
var count = dataset.getValue(1, 1)
if(count > 0)
{
plugins.dialogs.showErrorDialog( 'Error!', 'The value "' + adhd + '" already exists!', 'OK')
form.elements.adhd.requestFocus(false)
}
Basically, you’re doing a SQL query to count how many records have the same value. If its’ more than 0 (there’s something with the exact same name) - then show a dialog.
Hope this helps.
Bob,
Thank you so much for the help!
Have a wonderful weekend.
Abrahim