- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:50 AM
I have a Script Include/Client Script that adds 27 months to a date field, the problem is it changes the date format to 2023-09-12 instead of 09-12-2023.
How can I update the client script to show the correct format?
Solved! Go to Solution.
- Labels:
-
Service Desk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 10:56 AM
Find the solution... Added this line of code
g_form.setValue('certificate_expiration_date',formattedDate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:55 AM
can you share your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:56 AM
see below code and make changes as per your need
function addMonthsToField(fieldName, monthsToAdd) {
var field = g_form.getControl(fieldName);
if (field) {
var fieldValue = g_form.getValue(fieldName);
if (fieldValue) {
var glideDateTime = new GlideDateTime();
glideDateTime.setDisplayValue(fieldValue);
glideDateTime.addMonthsLocalTime(monthsToAdd);
var formattedDate = glideDateTime.getDisplayValue();
g_form.setValue(fieldName, formattedDate);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 12:11 PM
Here is the Client Script I'm using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 12:50 PM
Hello @John H1 ,
Kindly Update your Script include the Code as follows and try if you get expected output:
getEndDate: function() {
var issue_date = this.getParameter('sys_parm_issue_dt');
var days = this.getParameter('sys_parm_how_many_months');
var temp=issue_date.split('-');
issue_date=temp[2]+'-'+temp[1]+'-'+temp[0]
var gdt = new GlideDateTime(issue_date);
gdt.addDays(days);
var end_date=gdt.getLocalDate().getByFormat('dd-MM-yyyy');
return end_date
},
If my answer solves your issue please mark it as Helpful 👍 and Accepted✔️ based on impact.
Thanks & Regards,
Sunny R