- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 10:55 PM
Hi
Need help on below requirement. Can someone help on this?
we need to compare two fields and one field value shouldn't be exceeded and it should be negative always.
we have written onchange client script to allow only negative values but not able to compare with other field and restrict with less values. From the below screenshot, Accum should allow only less values than cost and always negative values. Any inputs really helps me alot
Thanks & Regards,
Anusha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 01:00 AM
I shared script below.
Sharing updated script again
try that and share your updates, it should be onChange on Accum variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('accum');
// Ensure Accum is negative
if (parseInt(newValue) >= 0) {
g_form.showFieldMsg('accum_to_retire', 'Accum must be a negative value', 'error');
g_form.clearValue('accum_to_retire');
return;
}
// Compare Accum with Cost
var cost = g_form.getValue('cost');
if (parseFloat(newValue) >= parseFloat(cost)) {
g_form.showFieldMsg('accum_to_retire', 'Accum must be less than Cost', 'error');
g_form.clearValue('accum_to_retire');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 11:05 PM
both the variables are editable and of type string?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 11:11 PM
Yes, Ankur
Regards,
Anusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 11:13 PM
check script shared below for onChange on Accum
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 11:38 PM
Hi Ankur,
It is not working and allowing users to enter positive values and greater values. Can you please verify once and help me . Also, showing some javascript error pop up on browser
Below script is working to allow negative numbers but we need to allow less values as well than cost field value
Thanks & Regards,
Anusha