Target date is not auto populated in problem record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 10:19 PM
We want to update the target date field in the problem record automatically. It will update after 21 days of the opened date. This field should be read only.
We tried through one onload script and script include. It is working. But when we implement the notification for the problem record, the target date field is not coming because of the onload script. Then
We have created one business rule for the target date auto populate.
When condition - before/insert
Advanced -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 10:34 PM
Hello @sukanya kotni
You are calling script include in wrong manner.
Use below code-
(function executeRule(current, previous /*null when async*/) {
var cdt = current.getValue('opened_at');
var ans = new UserTimeZone().setQuarterlyValidDate(cdt);
var date = new GlideDate(ans);
current.u_rca_target = date;
})(current, previous);
//////////////////////////////
var UserTimeZone = Class.create();
UserTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setQuarterlyValidDate: function(eDate) {
var dta = gs.getSession().getUser().getDateFormat();
var gr = new GlideDateTime();
gr.setDisplayValue(eDate, dta);
var gdtLocal = new GlideDateTime();
//gdtLocal.getLocalTime();
var offset = gdtLocal.getTZOffset();
gr.setNumericValue(gr.getNumericValue() + offset);
gr.addDays(21);
gr.getDisplayValue();
return this._convertToGlideDate(gr, dta);
},
_convertToGlideDate: function(gdt, fdta) {
var gd = new GlideDate();
gd.setValue(gdt.getValue());
var ft = fdta.split(" ")[0];
var d = gd.getByFormat(ft);
d = d + ' 23:59:59', fdta;
return d;
},
datefieldDiffCal: function() {
//var currentDate = gs.now();
var currentDate = new GlideDate();
var timeZone = gs.getSession().getTimeZoneName();
var start = new GlideScheduleDateTime(this.getParameter('date_1'));
var end = new GlideScheduleDateTime(currentDate);
start.setTimeZone(timeZone);
end.setTimeZone(timeZone);
//gs.log('dates'+ start+end);
//gs.log('dates1'+ dt.split(" "));
return gs.dateDiff(start,end, true);
},
type: 'DateTimeZone'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 01:57 AM
Hi @Harsh_Deep ,
Thank you for the respose.
I have tried as you mentioned in the above. The target field was not populated.
Thanks,
Sukanya. K