Change planned dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2024 05:20 AM
Hi,
I have a custom field 'set flag' on change request which should be set to true if planned start dates and planned end dates falls in between defined maintenance schedule. There is a schedule which contains 9 schedule entries if planned start date and planned end date falls in between any of the schedule entry, and if category or service offering contains sap then flag should be set to true. For this i have defined a BR with below code but it is not working. Can any one please help me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2024 10:45 AM
Hi,
Can you try below updated code:
(function executeRule(current, previous /*null when async*/) {
current.u_sap_me_flag = false;
// Initiate variables
var chg_start_dt = current.getValue('start_date'); // Use getValue for GlideDateTime
var chg_end_dt = current.getValue('end_date'); // Use getValue for GlideDateTime
gs.info('DEBUG JS: start date = ' + chg_start_dt);
gs.info('DEBUG JS: end date = ' + chg_end_dt);
var chg_cat = current.getValue('category');
var chg_srv_off = current.getValue('service_offering');
gs.info('DEBUG JS: chg cat = ' + chg_cat);
gs.info('DEBUG JS: service offering = ' + chg_srv_off);
// Check if category or service offering is related to SAP
if (chg_cat.indexOf("SAP") > -1 || chg_srv_off == "019c5daa1b83f1106bdb1f87b04bcb47") {
var gr = new GlideRecord('cmn_schedule_span');
gr.addQuery('schedule', '510750da1b34de90c14da9b7b04bcb0d'); // Your schedule
// Query for spans where the change request start and end date fall within schedule span
var qc1 = gr.addQuery('start_date_time', '<=', chg_start_dt);
qc1.addOrCondition('end_date_time', '>=', chg_start_dt);
var qc2 = gr.addQuery('start_date_time', '<=', chg_end_dt);
qc2.addOrCondition('end_date_time', '>=', chg_end_dt);
gs.info('DEBUG JS: Encoded query: ' + gr.getEncodedQuery());
gr.query();
if (gr.hasNext()) {
current.u_sap_me_flag = true; // Set flag to true if any schedule matches
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2024 09:19 PM - edited ‎10-22-2024 06:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2024 02:15 PM
Hi,
Can you try below updated one.
(function executeRule(current, previous /*null when async*/) {
current.u_sap_me_flag = false; // Default the flag to false
// Initiate variables
var chg_start_dt = new GlideDateTime(current.getValue('start_date')); // Ensure GlideDateTime is used
var chg_end_dt = new GlideDateTime(current.getValue('end_date')); // Ensure GlideDateTime is used
gs.info('DEBUG JS: start date = ' + chg_start_dt.getDisplayValue());
gs.info('DEBUG JS: end date = ' + chg_end_dt.getDisplayValue());
var chg_cat = current.getValue('category');
var chg_srv_off = current.getValue('service_offering');
gs.info('DEBUG JS: chg cat = ' + chg_cat);
gs.info('DEBUG JS: service offering = ' + chg_srv_off);
// Check if category or service offering is related to SAP
if (chg_cat.indexOf("SAP") > -1 || chg_srv_off == "019c5daa1b83f1106bdb1f87b04bcb47") {
var gr = new GlideRecord('cmn_schedule_span');
gr.addQuery('schedule', '510750da1b34de90c14da9b7b04bcb0d'); // Your maintenance schedule ID
// Narrower query: find schedule entries that completely encompass the change request start and end date
var qc = gr.addQuery('start_date_time', '<=', chg_start_dt);
qc.addCondition('end_date_time', '>=', chg_end_dt); // Ensure both dates fit in the schedule span
gs.info('DEBUG JS: Encoded query: ' + gr.getEncodedQuery());
gr.query();
if (gr.hasNext()) {
current.u_sap_me_flag = true; // Set flag to true if both start and end date fall within the schedule
gs.info('DEBUG JS: Flag set to true as dates fall within schedule.');
} else {
gs.info('DEBUG JS: No matching schedule span found.');
}
} else {
gs.info('DEBUG JS: Category or service offering is not related to SAP.');
}
})(current, previous);