- 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:57 PM
Hi @anushadande1793 ,
You may try with the following Onchange Client script on Accum field
function onChange(control, oldValue, newValue, isLoading) {
|
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 02:29 AM
Thank you All.
It helps me a lot.