creating a comments field and making it mandatory for approvals on portal view

Rahul Raja Sami
Tera Guru

Hi 

When the Request is approved or rejected using approvals on portal page then I want to make the comments mandatory (need to create a comments field first).

 

How to achieve this?

something like this

RahulRajaSami_0-1685035466995.png

 

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

HI @Rahul Raja Sami ,
I trust you are doing great.

  1. Create a Business Rule: First, create a business rule that triggers when the Requested Item (RITM) is approved or rejected. This rule will run when the approval or rejection occurs and will perform certain actions.

  2. Customize the RITM form: Modify the RITM form to include a mandatory comments field. You can achieve this by adding a new field to the form or marking an existing field as mandatory. This ensures that when the RITM is approved or rejected, the person making the decision must provide comments.

  3. Capture the comments: In the business rule, capture the comments entered by the approver or rejecter. You can use server-side JavaScript or any other scripting language supported by ServiceNow. Retrieve the comments from the form and store them in a variable.

  4. Update the request record: Once you have captured the comments, update the associated request record with the comments provided. This ensures that the comments are linked to the original request.

  5. Display comments on the portal: Modify the portal view to display the approval or rejection comments to the end user who raised the request. You can do this by customizing the relevant portal page or widget. Retrieve the comments from the request record and display them in a user-friendly format on the portal.

// Capture comments from the RITM form
var comments = current.comments;

// Update the associated request record with the comments
var request = new GlideRecord('sc_request');
request.addQuery('ritm', current.request_item);
request.query();
if (request.next()) {
    request.comments = comments;
    request.update();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



hi amit,
can you please go through my question once again, please.