Change UI Action for Submit for Approval

ymerkle
Tera Contributor

I would like to change the UI Action "Submit for Approval" on the Quote Management Data Model application, so that the quote is not set to approved by clicking on the button but rather following this logic:
If discount percentages are set on the quote:

<5% = Auto-approved

5%>x<10% = Sales Manager to approve

15%> = Sales Manager to approve

 

Screenshot 2025-08-21 at 19.08.37.png

I have pasted the same question as well in the CSM forum, but I think this one fits better for my question.

Any tip how I would able to implement it is much appreciated. Thanks in advance.

3 REPLIES 3

G Ponsekar
Mega Guru

Hi @ymerkle ,

 

Inside the UI Action script, you'll need to:

 

  • Use if/else if/else statements to apply your approval rules based on the discount percentage:
    • < 5%: Automatically set the quote's approval state to "Approved" and update the record.
    • 5% > x < 10% or > 15%: Set the quote's approval state to "Requested" or "Pending Approval" and trigger an approval workflow or business rule for the Sales Manager.
  • Trigger the approval workflow/business rule: You can achieve this by using new GlideFlow("your_workflow_name").start(); for Flow Designer or gs.eventQueue("your.approval.event", current, "your_group_name", "your_approver_role"); for a Business Rule and events. 
 
javascript
// Example UI Action Script (customize based on your Quote Management application's field names)
// Assuming a 'discount_percentage' field on your quote table

var discount = current.discount_percentage; 

if (discount < 5) {
    current.approval = 'approved'; 
    gs.addInfoMessage("Quote automatically approved due to discount percentage.");
} else if (discount >= 5 && discount < 10 || discount >= 15) { 
    current.approval = 'requested'; // Set to 'Requested' or a 'Pending Approval' state    gs.addInfoMessage("Quote submitted for Sales Manager approval."); 
    // Trigger Flow Designer workflow or Business Rule for Sales Manager approval
    // Option 1: Flow Designer (assuming a flow named "SalesManagerApproval")
    new GlideFlow("SalesManagerApproval").start(); 
    // Option 2: Business Rule (triggering an event that a BR listens to)
    // gs.eventQueue("quote.sales.manager.approval", current, "Sales Manager Group Name", ""); }
current.update(); // Update the quote recordaction.setRedirectURL(current); // Stay on the current quote record

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

ymerkle
Tera Contributor

Hi GP,

 

Thanks a lot for supporting me in the setup of my approval workflow. As I am pretty new to ServiceNow, I would also appreciate your help in setting up the respective flow. Is that something you can also assist me with? I have created the following group to which the approval should go to:

ymerkle_0-1755856037552.png

 

Thanks a lot and best regards

ymerkle
Tera Contributor

I have tried the script, but it is not working for me. I have even adjusted only to set status to approved if below 0 and set status to in_review if above 0; but it always stets the State to approved even if it is above 0:

ymerkle_0-1755876317569.png

ymerkle_1-1755876345618.png

Anyone any idea?