Call a script Include from UI Action

hadron_collider
Tera Contributor

Hello!

 

 

Im working on a functionality that will allow to change the status of a record when a button is clicked.

 

I have an UI Action (client) so that when the button is clicked 'reason for reject' shows up and is set to mandatory:

kata90_0-1704814723056.png

 

 

I want the approver to be obliged to provide 'reject reason' to be able to change the status to 'rejected'.

 

Here is my UI action:

 

kata90_1-1704814816919.png

 

is it possible to call Script Include that will handle the logic of the record update? (changing the field value to 'rejected' and adding the 'reject reason').

 

 

Thank you in advance!

 

1 ACCEPTED SOLUTION

I corrected this in my reply above, see this

if( g_form.getValue('u_activity')== ''){   // this if was wrong
return false; //Abort submission 
}
-Anurag

View solution in original post

15 REPLIES 15

TRy this

function runClientCode(){
	//alert("test");
	var activityField = g_form.getControl('u_activity');
    // Make the field visible
    g_form.setDisplay('u_activity', true);
    // Make the field mandatory
    g_form.setMandatory('u_activity', true);
if( g_form,.getValue('u_activity')== ''){   // this if was wrong
return false; //Abort submission 
}


//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'expense_reject_action'); //MUST call the 'Action name' set in this UI Action
}
 

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();

//Server-side function
function runBusRuleCode(){

current.u_reject_reason = 'Rejected';
current.exp_amount = 0;
current.update();

gs.addInfoMessage('Record rejected successfully.');
gs.addInfoMessage('You did it!');
action.setRedirectURL(current);

}
-Anurag

thanks! 

 

But im getting an error from line 8:

 

kata90_0-1704816710166.png

not sure what is this condition??

I corrected this in my reply above, see this

if( g_form.getValue('u_activity')== ''){   // this if was wrong
return false; //Abort submission 
}
-Anurag

Many thanks Anurag!

Ankur Bawiskar
Tera Patron
Tera Patron

@hadron_collider 

you can simply use the same UI action code without server side

you can use g_form.save() to save the record in client side code

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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