The CreatorCon Call for Content is officially open! Get started here.

Conversion of date in a client script

Karen16
Giga Guru

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

1 ACCEPTED SOLUTION

Ct111
Tera Sage

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 

 

 

View solution in original post

4 REPLIES 4

Ct111
Tera Sage

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 

 

 

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

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

Just use "parseInt(<string>)" to convert string to int.

var month = "7";
var intMonth = parseInt(month) + 1;