On Change client script not working on integer like I'd expect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 08:31 AM
I'm working on the OnChange client script below, expecting the error message to appear if a user tries to increase the value above 100 from the current value. I'd suspect since it's an integer my If statement would work, but it's not capturing the data as I'd expect. Any help is appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 08:35 AM
Hi @phaug ,
Use parseInt for old values as well
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var newVal = parseInt(newValue);
if (newVal > (parseInt(oldValue) + 100)) {
g_form.addErrorMessage("Cannot increment the priority sequence by more than 100.");
g_form.setValue(oldValue.toString());
}
}
Please mark it as solution proposed and helpful if its serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 08:40 AM
I tried that change and it's still not working. The error message does not appear on the screen and I can still change the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:28 AM
Hi @phaug ,
I have tried in my PDI its working fine for me
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var newVal = parseInt(newValue);
if (newVal > (parseInt(oldValue) + 100)) {
g_form.addErrorMessage("Cannot increment the priority sequence by more than 100.");
g_form.setValue('u_integer',oldValue.toString());
}
}
Make sure onchange on integer field and ui type-all put info messages to testing.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:38 AM - edited 12-19-2023 07:10 AM
I'm doing the same thing and it's still not working. I noticed if it's less than 1,000 it will show the error, but it does it for every single change. Doesn't matter if it's less than 100 or not. It just always throws the error, but never resets the number.