When close is filled and save it should get aslo reflected in activity log of change mgmt

avinashdubey103
Tera Guru

HI , I have a requirement to update activity log in the notes section when the close note are filled and saved :

I have used this script , it is working but giving the following error:

Code:L

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}


// Check if the Close Notes field is not empty
if (newValue) {
// Get the current user's name (or any other identifier you want to use)
var currentUser = g_user.getUserName();

// Get the current date and time
var currentDate = new Date();
var formattedDate = currentDate.toISOString();

// Construct the comment to be added to the activity log
var comment = currentUser + ' updated Close Notes on ' + formattedDate + ': ' + newValue;

// Add the comment to the 'Notes' tab in the activity log
// g_form.addInfoMessage(comment);
var activityRecord = new GlideRecord('sys_journal_field');
activityRecord.initialize();
activityRecord.setNewGuidValue();
activityRecord.setValue('element', 'comments');
activityRecord.setValue('type', 'comment');
activityRecord.setValue('value', comment);
activityRecord.setValue('group', g_form.getUniqueValue()); // Link to the change record
activityRecord.insert();
}

//Type appropriate comment here, and begin script below

}

 

ErrorL

avinashdubey103_0-1701429194871.png

 

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Why you are using script to update activity logs?

You can configure the fields that should appear in activity log by making small change.

 

https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/administer/form-administra...

 

Follow below steps:

1. Open any change record:

2. Scroll to Activities in Notes section.

Screenshot 2023-12-01 at 4.54.07 PM.png

3. Click on the Funnel icon to configure filter

Screenshot 2023-12-01 at 4.55.50 PM.png

4. Add the Close Notes field. and save the selection.

Screenshot 2023-12-01 at 4.57.12 PM 1.png

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

1 REPLY 1

Anil Lande
Kilo Patron

Hi,

Why you are using script to update activity logs?

You can configure the fields that should appear in activity log by making small change.

 

https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/administer/form-administra...

 

Follow below steps:

1. Open any change record:

2. Scroll to Activities in Notes section.

Screenshot 2023-12-01 at 4.54.07 PM.png

3. Click on the Funnel icon to configure filter

Screenshot 2023-12-01 at 4.55.50 PM.png

4. Add the Close Notes field. and save the selection.

Screenshot 2023-12-01 at 4.57.12 PM 1.png

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande