- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 04:33 AM
var WorknotesUpdater = Class.create();
WorknotesUpdater.prototype = {
initialize: function() {
},
// Function to update worknotes for an incident
updateWorknotes: function(currentIncident, additionalNotes) {
try {
if (currentIncident && additionalNotes) {
var workNotes = currentIncident.work_notes.getJournalEntry(1); // Get existing worknotes
var newWorkNotes = additionalNotes + '\n\n' + workNotes; // Append new notes
currentIncident.work_notes = newWorkNotes; // Update the worknotes field
currentIncident.update(); // Save the incident
return true;
}
} catch (ex) {
gs.error("Error updating worknotes: " + ex);
}
return false;
},
type: 'WorknotesUpdater'
};
In this script , I'm updating the worknotes but i wanted to update through particular user
Please help me with your suggestions and solutions.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 04:38 AM
@varshinin You can use the GlideImpersonate API to impersonate as a user in the script and post a worknote on their behalf.
var user = gs.getUserDisplayName();
gs.print ("The current user display name is: " + user);
var impUser = new GlideImpersonate();
impUser.impersonate("62826bf03710200044e0bfc8bcbe5df1");
var user = gs.getUserDisplayName();
gs.print ("The impersonated user display name is: " + user);
For more information, please refer to the docs here https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/GlideImpersonateAPI#GI-c...
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 04:38 AM
@varshinin You can use the GlideImpersonate API to impersonate as a user in the script and post a worknote on their behalf.
var user = gs.getUserDisplayName();
gs.print ("The current user display name is: " + user);
var impUser = new GlideImpersonate();
impUser.impersonate("62826bf03710200044e0bfc8bcbe5df1");
var user = gs.getUserDisplayName();
gs.print ("The impersonated user display name is: " + user);
For more information, please refer to the docs here https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/GlideImpersonateAPI#GI-c...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 04:42 AM
@Sandeep Rajput Thanks for the solution.
it is working now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 09:55 AM
@Sandeep Rajput this script works fine in global ,
But GlideImpersonate is not allowed in scoped application . please suggest how i can achieve the same on scoped application.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2023 10:54 AM
@varshinin Create a script include in Global scope, create updateWorknotes function inside it and put the impersonation code there. Call this script include inside your scoped application by using global.<ScriptIncludeName> specifier.
Hope this helps.