- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2022 11:54 PM
Hi All,
I have two fields on incident form Say A(type- journal_input) and B(type- string). The current behaviour whatever comments we add in field A gets copied in field B.
The requirement is- When some user type some comments in field A, irrespective of that users timezone, the comments should show time(in PDT timezone) along with PDT timezone in field A and same should be shown in field B for anyone who is viewing that record.
In short, irrespective the timezone/ system timezone of the user who added comments and the user timezone/system timezone who is viewing that incident record, the comments should show time(in PDT timezone) along with PDT timezone.
Is it possible to achieve this?
If yes, how can we implement this?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2022 08:42 AM
try this
(function executeRule(current, previous /*null when async*/ ) {
var arr = [];
// get only comment
var comm_plan = new GlideRecord('incident_alert');
comm_plan.addQuery('sys_id', current.sys_id);
comm_plan.query();
while (comm_plan.next()){
var journal = new GlideRecord('sys_journal_field');
journal.addQuery('element', 'u_field_a');
journal.orderByDesc('sys_created_on');
journal.query();
while (journal.next()) {
var time = new GlideDateTime(journal.sys_created_on);
var targetTimezone = 'PDT'; // ensure you give correct timezone Abbreviation
var tz = Packages.java.util.TimeZone.getTimeZone(targetTimezone);
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
var comment = journal.value;
arr.push(time + ' PDT- ' + '\n' + comment + '');
}
}
comm_plan.u_field_b = arr.toString();
comm_plan.update();
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 02:56 AM
Hi,
your script is inside BR so I assume you wish to get comments for current incident only
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 03:17 AM
we are fetching records of sys journal fields and sorting by created on. In var comment,we are storing journal.value so what is happening is if i add some comments to the incident, along with current comment, field B gets updated with all records of sys journal field table with field A. This should work as getJournalEntry(-1). getJournalEntry(-1) partially works for me it shows the comments specific to the incident, but excluding current comment, previous comments gets back to IST, only the current updated comments shows time in PDT.