- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 02:55 AM - edited 11-09-2024 02:57 AM
Hi All,
I am working on the below script:
UI policy:
function onCondition() {
var DDSLA = new GlideAjax("incident_Utils");
DDSLA.addParam("sysparm_name", "ValidateDueDateSLA");
DDSLA.addParam("sysparm_incidentId", g_form.getUniqueValue());
DDSLA.getXML(ValidateDuedate);
}
function ValidateDuedate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("get si value " + answer);
if (answer == 'true') {
alert("Less than or equal to 12 / 18 months");
g_form.clearValue('u_due_date_missed_sla_rationale');
g_form.setMandatory('u_due_date_missed_sla_rationale', false);
g_form.setVisible('u_due_date_missed_sla_rationale', false);
} else {
alert("test greater than 12 and 18 months");
g_form.setVisible('u_due_date_missed_sla_rationale', true);
g_form.setMandatory('u_due_date_missed_sla_rationale', true);
}
}
Script include:
ValidateDueDateSLA: function() {
var recordId = this.getParameter('sysparm_incidentId);
var isUpdated = false;
var gr = new GlideRecord('incident');
if (gr.get('7b3d3451eb6dd6142008fcbbcad0cd87')) {
var identifiedStr = gr.getValue('u_identification_date');
var BusinessDueStr = gr.getValue('u_business_activities_due_date');
var Dep = gr.getValue('u_dependency');
var IdentifiedDate = new GlideDate();
IdentifiedDate.setValue(identifiedStr);
gs.addInfoMessage('Converted into Date identified: ' + IdentifiedDate);
var BusinessDueDate = new GlideDate();
BusinessDueDate.setValue(BusinessDueStr);
gs.addInfoMessage('Converted into Date BADD: ' + BusinessDueDate);
var IdentifiedDatePlus12Months = IdentifiedDate.addMonthsLocalTime(12); //addMonthsLocalTime
var IdentifiedDatePlus18Months = IdentifiedDate.addMonthsLocalTime(18);
var isBADDWithIn12Months = BusinessDueDate <= IdentifiedDatePlus12Months;
var isBADDWithIn18Months = BusinessDueDate <=IdentifiedDatePlus18Months;
gs.addInfoMessage('IdentifiedDatePlus12Months : ' + IdentifiedDate); // Just for debugging in background script, to be removed from Business rules
gs.addInfoMessage(''IdentifiedDatePlus18Months : ' + BusinessDueDate);
if (Dep == 'no' && isBADDWithIn12Months) {
isUpdated = true;
} else if (Dep == 'yes' && isBADDWithIn18Months) {
isUpdated = true;
}
}
return isUpdated;
},
I am facing issue in the below scenario:
identification date = 28/10/2024
Business Due date = 28/10/2026
But when adding 18 months in script include using AddMonths(18) to identified date... It was adding more months as below
getting Identification date = 28/04/2027
I am not understanding what is the issue not able to replicate Please help me....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 04:11 AM
Hi @Are Kaveri ,
I got your issue, silly mistake
As per your existing code you are adding 12+18=20 month in "IdentifiedDate".
replace below code
var IdentifiedDatePlus12Months = IdentifiedDate.addMonthsLocalTime(12); //addMonthsLocalTime
var IdentifiedDatePlus18Months = BusinessDueDate.addMonthsLocalTime(18);
or if you want to add 12 and 18 month in same date then you have to do below.
var IdentifiedDatePlus12Months = IdentifiedDate.addMonthsLocalTime(12); //addMonthsLocalTime
IdentifiedDate.addMonthsLocalTime(-12);
var IdentifiedDatePlus18Months = BusinessDueDate.addMonthsLocalTime(18);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 04:11 AM
Hi @Are Kaveri ,
I got your issue, silly mistake
As per your existing code you are adding 12+18=20 month in "IdentifiedDate".
replace below code
var IdentifiedDatePlus12Months = IdentifiedDate.addMonthsLocalTime(12); //addMonthsLocalTime
var IdentifiedDatePlus18Months = BusinessDueDate.addMonthsLocalTime(18);
or if you want to add 12 and 18 month in same date then you have to do below.
var IdentifiedDatePlus12Months = IdentifiedDate.addMonthsLocalTime(12); //addMonthsLocalTime
IdentifiedDate.addMonthsLocalTime(-12);
var IdentifiedDatePlus18Months = BusinessDueDate.addMonthsLocalTime(18);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 04:22 AM
Are the custom fields you added to the incident table the type of date/time or date? What are you seeing in the 4 infoMessages (after correcting the extra apostrophe in the fourth so that it displays)? Are the results the same if you addMonthsUTC instead?