- 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-11-2022 01:44 AM
Hi,
the time when comments is added is the current system time
just convert it to PDT using link I shared
something like this; just enhance it
(function executeRule(current, previous /*null when async*/ ) {
var time = new GlideDateTime();
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);
// get only comment
var comment = current.field_a.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
comment = comment.replace(dateRE, '');
current.field_b = comment + ' PDT Time ' + time;
})(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-11-2022 05:09 AM
I also want previous comments(history) added in field B like below-
2022-04-11 05:27:09 PDT
test5
2022-04-11 05:25:39 PDT
test4
2022-04-11 05:23:09 PDT
test3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 07:33 AM
Hi,
then query sys_journal_field; get the created on time; convert that to PDT and print it with value
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-11-2022 10:52 PM
could you please provide the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 11:26 PM
I already shared the logic yesterday.
query sys_journal_field; get the created on time; convert that to PDT and print it with value
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader