Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set due date using client script?

nthumma
Giga Guru

I want to set due date = current date + 3 days ?

Thanks in advance.

1 ACCEPTED SOLUTION

Hello srnewbie,



You beat me to it!



Here is my code, yours look way cleaner. Thank you for sharing your solution.



function onLoad() {


var today = new Date();


var inThreeDays = new Date();


inThreeDays.setDate(today.getDate() + 3);


var inThreeDaysFormatted = inThreeDays.getFullYear()   + '-' + ('0' + (inThreeDays.getMonth() + 1)).slice(-2) + '-' + ('0' + (inThreeDays.getDate() + 1)).slice(-2);


console.log(inThreeDaysFormatted);


g_form.setValue('due_date',inThreeDaysFormatted   );


 


}



Thanks.


View solution in original post

10 REPLIES 10

edwin_munoz
Mega Guru

Hello srnewbie,



No need for GlideAjax in this one. You can make use of the native javascript Date class,



https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date



I'll post example code later today.



Thannks