Urgent help for script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 10:50 AM - edited ‎01-24-2024 10:50 AM
Business rule is created for state change in sc task request for based on journal entry change made by non assignment group members. Worknote is update on script to highlight this development. But when members update work note this work note abd worknote added via script is comming in same line. Worknote is script mentioned as updated by system..
Worknote added by agent to update as separate entry with user name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 04:59 AM
Can you please share a snip of the worknotes if possible and your script to debug it further ?
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 01:29 AM
Here are the steps to implement this:
1. Create a new Business Rule on the sc_task table.
2. Set the 'When to run' section as follows:
- When: before
- Insert: unchecked
- Update: checked
- Delete: unchecked
- Query: unchecked
3. In the 'Advanced' section, write a script to check if the work_notes field has been updated and if the user is not a member of the assignment group. If these conditions are met, add a new line to the work_notes field and append the new work note. Here is a sample script:
javascript
(function executeRule(current, previous /*null when async*/) {
// Check if work_notes has been updated and if the user is not a member of the assignment group
if (current.work_notes.changes() && !current.assignment_group.contains(gs.getUserID())) {
// Add a new line to the work_notes field and append the new work note
current.work_notes = "\n" + current.work_notes;
}
})(current, previous);
4. Save the Business Rule.
This script checks if the work_notes field has been updated and if the user is not a member of the assignment group. If these conditions are met, it adds a new line to the work_notes field and appends the new work note. This should ensure that work notes added by agents are updated as separate entries with the user name.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 01:55 AM
To achieve this, you can use the gs.getUserDisplayName() method to get the name of the current user and append it to the work note. Here are the steps:
1. Create a new Business Rule or modify the existing one.
2. In the script section, use the gs.getUserDisplayName() method to get the current user's name.
3. Append the user's name to the work note.
4. Use the addWorkNotes() method to add the work note to the record.
Here is a sample code:
javascript
(function executeRule(current, previous /*null when async*/) {
// Get the current user's name
var userName = gs.getUserDisplayName();
// Append the user's name to the work note
var workNote = userName + ": " + current.work_notes.getJournalEntry(1);
// Add the work note to the record
current.work_notes = workNote;
// Update the record
current.update();
})(current, previous);
Please note:
- This code assumes that the work note is stored in the 'work_notes' field.
- The getJournalEntry(1) method is used to get the most recent journal entry.
- The update() method is used to save the changes to the record.
- This code should be placed in the 'Advanced' section of the Business Rule.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
Link - https://nowgpt.ai/