- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 09:15 PM
Hi I have this script onChange for planned start date, and one for end date as well pasted below which is working as I need it to.
I'm kind of still learning javascript, so basically what I wanted to know when i first created the script I had the state value in quotes if (state >= '-2'). This made the script run for change request in all states, but without quotes it works fine. Can you explain why, and why it just didn't give an error?
var state = g_form.getValue('state');
if (state >= -2) {
g_form.showFieldMsg('start_date', 'Please provide explanation for changing the planned start date in the notes');
g_form.setMandatory('work_notes', true);
}
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 09:23 PM
Hi,
if you give value on quotes it will take as a string but when you give without quotes it will take as an number and check all the state values as per that number will execute.
Hope you it helps you to understand.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 09:23 PM
Hi,
if you give value on quotes it will take as a string but when you give without quotes it will take as an number and check all the state values as per that number will execute.
Hope you it helps you to understand.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 09:48 PM
Thank you!