- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 09:30 AM
Hi,
As a University, it is more common to think of Fiscal Year instead of Calendar Year. I'm trying to create a Client Script which will calculate the current FY on the fly to display a value to the users. I need to utilize current date and determine which month it is so I can use either the current year, or the next year if the months are Jul through Dec. I'm able to substring out the year and month, but these turn into strings and not integers so I can't simply add 1 to the 'year' to accomplish this. I've tried every method of java to add year, add day, plus, etc to increase the date by a year, but nothing has worked.
Has anyone else done anything similar to this in a client script and have any advice about moving forward? I think the easiest path would be to take the substring year and force it to be an integer, but I'm open to any suggestions.
Thanks,
Karen
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 10:05 AM
To add year, month and day you would have to use GlideDateTime api and it's method because that is what is accepted in Servicenow.
Please refer this link for more details , you will get your answer for year, month, days addition:
https://developer.servicenow.com/print_page.do?release=paris&category=null&identifier=c_APIRef&module=api
Mark my Answer as Correct and Helpful if it helps
Note : you can test all these scripts in background scripts and check the working as well before implementing in your code just to get gist of it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 10:05 AM
To add year, month and day you would have to use GlideDateTime api and it's method because that is what is accepted in Servicenow.
Please refer this link for more details , you will get your answer for year, month, days addition:
https://developer.servicenow.com/print_page.do?release=paris&category=null&identifier=c_APIRef&module=api
Mark my Answer as Correct and Helpful if it helps
Note : you can test all these scripts in background scripts and check the working as well before implementing in your code just to get gist of it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 10:43 AM
Hi,
This does not appear to work in client scripts. In order to get a date, I can only seem to use the regular java expression var curDate = new Date(); GlideDateTime and global.GlideDateTime return nothing for me.
Thanks,
Karen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 10:50 AM
Hello ,
Plz avoid doing date time calculation directly on client script rather call it from client script and use it in script include
Example for your reference : https://community.servicenow.com/community?id=community_question&sys_id=ff6aec04dbf89784fc5b7a9e0f96191e

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 03:21 PM
Just use "parseInt(<string>)" to convert string to int.
var month = "7";
var intMonth = parseInt(month) + 1;