How To Add A Worknote To A Task, When It’s Approved

ServiceNow Approvals – Adding A Worknote To The Task, When Approved ServiceNow, as one of the most comprehensive and scalable IT Service Management platforms, offers numerous features designed to streamline the flow of business processes. …

add worknote when approved

ServiceNow Approvals – Adding A Worknote To The Task, When Approved

ServiceNow, as one of the most comprehensive and scalable IT Service Management platforms, offers numerous features designed to streamline the flow of business processes.

One of these features is the Approvals process, which is integral for controlled and managed task progression.

An Introduction to ServiceNow Approvals

ServiceNow Approvals enable organizations to define, manage, and automate approval processes. These processes could be for change requests, incidents, or any record that needs a controlled authorization before progressing to the next phase. When utilized correctly, approvals ensure that changes and tasks are undertaken in a structured and auditable manner.

An aspect that can further enhance the Approvals feature is the ability to add worknotes to tasks upon approval. These worknotes provide an auditable history of comments or reasons related to the approval. This ensures better transparency, communication, and traceability of decisions made throughout the lifecycle of a task.

Practical Implementation with Scripting

To correctly add a worknote to the associated task upon its approval in the sysapproval_approver table, consider the following script:

// Business Rule Script to add worknote upon approval in sysapproval_approver table

(function executeRule(current, previous /*null when async*/ ) {

    // Fetch the associated task
    var taskRecord = new GlideRecord(current.document_id.sys_class_name);
    if (taskRecord.get(current.document_id)) {
        // Add a worknote to the associated task
        taskRecord.work_notes = "Task has been approved by " + gs.getUserDisplayName() + ".";
        taskRecord.update();

    }

})(current, previous);

Commentary on the Code:

  1. This script is designed for a Business Rule on the sysapproval_approver table.
  2. It checks if the state field of the approval record has changed to ‘approved’.
  3. If so, it fetches the associated task using the source_table and document_id fields from the current approval record.
  4. Once the associated task is fetched, it adds a worknote to the task indicating who approved it.
  5. gs.getUserDisplayName() is utilized to get the name of the current user – in this case, the approver.

Best Practices and Considerations

  1. Event-Based vs. Polling: Always prefer event-driven approaches (like the above Business Rule script) over periodic polling to check for record updates. It’s more efficient and real-time.
  2. Avoid Hardcoding: The above example is simple, but in real-world scenarios, avoid hardcoding statuses like ‘approved’. Instead, consider using constants or system properties.
  3. Performance: When creating Business Rules, be conscious of the performance impact. Ensure that the conditions are specific to reduce unnecessary rule executions.
  4. Auditability: Always ensure that the worknotes added provide meaningful information for audit purposes. Who did what, when, and possibly why, are key pieces of information.
  5. Testing: Before deploying any script, always test it in a sub-production instance to ensure it behaves as expected without side effects.

Concluding Thoughts

ServiceNow’s Approval process is more than just a gatekeeper mechanism; it’s a pivotal component of a robust ITSM strategy. Enhancing this feature with the ability to automatically add worknotes ensures better accountability and transparency. By adhering to best practices and utilizing ServiceNow’s powerful scripting capabilities, organizations can further optimize their workflows, enhance communication, and ensure compliance.

Whether you’re just starting out with ServiceNow or are a seasoned developer, the ability to intertwine approvals with worknotes will undoubtedly prove beneficial in your ServiceNow journey. Always remember, the key lies in the details, and with ServiceNow, every detail can be precisely managed and recorded.



What Do You Think About This Article?

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x