This Advanced Techniques post demonstrates how you can prevent certain values,
e.g. email addresses or titles, from being recorded doubly before they are
saved.
Click on "OK" and save the application with
the keyboard combination CTRL + S.
Assign the application to a position in the portal menu structure
and then open it in the browser.
On the edit page, record the following titles:
Title 1
Title 2
Title 2
2. Modify custom.js
To modify the "custom.js" file, please proceed
as follows:
The database field "Title", that is to be checked
in our example, will now be provided with a "sysident"
that is unique in the data group. To do that, select the data group
in the application structure and then
"Show data fields" from the Edit menu.
Open the properties dialog of the Title database field by double-clicking on it.
Then switch to the "Expert" tab. If this tab
is not available, please activate the
Expert options.
Here, click on
"Add attribute". In the "Attribute"
column, insert the attribute "sysident"
and in the "Value" column, insert a name which is unique
in the data group (e.g. "my_title").
Please note the attribute "sysident" should
be written in lower case.
Click on "OK".
6. Write JavaScript
Now switch to the edit page and open the properties dialog of the
OK button, which saves the data record, by
double-clicking on it.
Switch to the Script tab and click on
"Edit JavaScript for desktop".
Copy the script shown below into the script editor.
function checkTitle()
{
var l_oCheckUpResult = checkUpForDatabaseConflictBySysidentAndObject("sysident name", getElement("Edit field GUID"), false);
if(l_oCheckUpResult.bError)
{
alert("An error occurred!\n"+l_oCheckUpResult.iErrorId+": " + l_oCheckUpResult.strErrorDesc)
}
else
{
if(l_oCheckUpResult.bConflict)
{
// a conflict was found
// Option 1: Inform the user that the data record cannot be saved and cancel the saving process with return false;
//alert("This title has already been recorded!")
//return false;
// Option 2: Ask user if they'd like to save anyway
Check = confirm("This title has already been recorded!\nWould you like to save anyway?");
if(Check)
return true;
else
return false;
}
else
{
// No conflicts were found
return true;
}
}
return false;
}
In the row
var l_oCheckUpResult = checkUpForDatabaseConflictBySysidentAndObject("sysident name", getElement("Edit field GUID"), false);
you need to add the "sysident name" ("my_title" in our example) and the
GUID of the edit field.
The GUID of the "Title" edit can easily be identified
by switching to the
Application structure
tab on the right-hand side of the editor. Click on "OK" to save the script
and close the editor.
Here, the JavaScript function can be assigned to the button event
"onclick". This is done by clicking
on
"Add script". After the assignment
has been made, click on "OK".
Click on "OK" and save the application.
If a title is entered for a second time in the browser, the user is
informed accordingly.
Please note that this conflict check only works if the corresponding
data records are not created in the same millisecond range.