- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 09:21 AM
Hi,
I have a weird behaviour with a client script that should take place only on a submit of a new record, but it works on update too.
The script is very simple:
function onSubmit()
{
var gr = new GlideRecord('table');
gr.addQuery('key',g_form.getValue('key'));
gr.query();
if(gr.next()){
g_form.addErrorMessage('The record already exists');
g_form.setValue('key',''); //it delete the value
return false;
}
}
The script should check if a name is already present in a list when submitting a new record, and prevent it to submit, deleting the value.
It actually works, but it starts also when I update or save the record (with Update or Save Button), deleting the key field.
Weird, isn't it?
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 09:25 AM
Okay..you could put g_form.isNewRecord() to check if the record is new
If no, then return false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 09:27 AM
You must encapsulate your code inside
if (g_form.isNewRecord()) { if record is not submitted yet, means new record
}