due date needs to set based on the priority value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 10:09 AM
I need to set Due date based on the priority value. If priority is 1 then due date should needs to be updated with 20 days from creation date likewise if priority is 2 then due date would be 30 days from creation date. If priority is 3 then due date would be 60 days from creation date and if priority is either 4 or 5 then due date would be 120 days from creation date. I can able to update it but the issue I'm facing is due date is updating 7 hours more. for example; I selected priority 1 and created on 05-Aug-2024 02:09:20 and due date is updating as 25-Aug-2024 09:09:20. Below are the code which I wrote. Could someone please help me to fix it.
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2024 10:16 AM
Hi @Sanjay Kumar10 ,
Approach 1:
Sample below.
#ClientCallable Script Include
var CLProblemUtilsAJAX = Class.create(); CLProblemUtilsAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, { calculateDueDate: function(){ var priority = this.getParameter('sysparm_priority'); var gdt = new GlideDateTime(); if(priority >= 3){ return ''; } gdt.addDaysUTC(7 * parseInt(priority)); return gdt; }, type: 'CLProblemUtilsAJAX' });
#OnChange Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } var ga = new GlideAjax('global.CLProblemUtilsAJAX'); ga.addParam('sysparm_name', 'calculateDueDate'); ga.addParam('sysparm_priority', g_form.getValue('priority')); ga.getXMLAnswer(function(response) { if (!response) { g_form.clearValue('due_date'); g_form.setReadOnly('due_date', false); g_form.setMandatory('due_date', true); return; } g_form.setValue('due_date', response); g_form.setReadOnly('due_date', true); });
Approach 2:
For this ,use before business rule.
when to run before insert, update
condition priority is changes
(function executeRule(current, previous /*null when async*/) {
var datevalue = current.priority;
var days1;
if (datevalue == '1') {
days1 = 7; // P1
} else if (datevalue == '2') {
days1 = 12; // P2
} else if (datevalue == '3' || datevalue == '4' || datevalue == '5') {
current.setValue('due_date', ''); // Clear the due date
}
if (days1) {
var ed = new GlideDateTime();
ed.addDays(days1);
current.due_date = ed;
}
})(current, previous);
Mark the comment as a correct answer and also helpful once worked.
Thanks & Regards,
Sumanth Meda