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

This is very simplistic, but here is how I did it:



Client Script:


Capture.PNG


Script Include:


Capture2.PNG


Result:


Capture3.PNG


when I try this I get following error Access to Script Include HelloWorld blocked from scope.





Did you set the 'Accessible from' field to 'All application scopes'?


Yes.


I was able to set due date using JS as suggested by Edwin Munoz. below is my code


function setDueDate(num_of_days)


{


var days_to = parseInt(num_of_days);


var now = new Date();


now.setDate(now.getDate() + days_to);


var duedate = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1)).slice(-2) + '-' + ('0' + now.getDate()).slice(-2) + ' ' + ('0' + (now.getHours())).slice(-2) + ':' + ('0' + now.getMinutes()).slice(-2) + ':' + ('0' + now.getSeconds()).slice(-2);


g_form.setValue('due_date',duedate);




}




Thanks for all the help Mike Allen


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.