Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Flow Designer is Not Triggering with state change with custom button

THDR
Giga Contributor

I have a flow designer which is not triggering

THDR_0-1763649111708.png

 

It triggers when I manually change the state in the Table List, it will trigger. 

However I have also created a button which basically changes the state to "pending approval"

Which only changes the state but does not trigger the flow. 

 

THDR_1-1763649279465.png

This is the code, which changes the state, but not triggering the flow. 

 

function onClick(g_form) {
    // Validate required fields
    if (!g_form.getValue('target_date')) {
        g_form.addErrorMessage('Target date is required');
        return false;
    }
    
    if (!g_form.getValue('reason_and_areas_of_focus')) {
        g_form.addErrorMessage('Reason is required');
        return false;
    }
	// Set assignment group BEFORE state change
    g_form.setValue('assignment_group', '43a3940a4715b250e12bcea5936d437c');
    
    // Set state FIRST
    g_form.setValue('state', 'pending_approval');
    
    // Force save - use save() instead of submit()
    g_form.save();
    
    // Show message after save starts
    g_form.addInfoMessage('Request submitted for approval!');
}


Kindly assist

Thank you

2 REPLIES 2

M Iftikhar
Tera Sage

Hi @THDR,

 

Please test this UI Action on a new record. You've set the Flow trigger to "Run: Once"—have you previously executed this flow for this record?

 
Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

Ankur Bawiskar
Tera Patron
Tera Patron

@THDR 

make sure you run Flow as System User

are you sure the record is getting saved using workspace client script and state is getting updated in database?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader