- 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: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:30 AM
Thank you arka for the quick answer! Now it's okay.
I still wonder why they call it "onSubmit" and it works on Update too. 😕
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2018 09:33 AM
Hi Gabriele,
onSubmit client scirpt trigger whenever an update / insert opration is tried with DB.
This is expected behavior, same client script gives you more control with g_form.isNewRecord() when record is not yet inserted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2018 09:34 AM
Not sure..I think its a terminology that SNOW uses when any client side function tries to interact with the server...