- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 07:41 AM
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:
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:
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 08:14 AM
I corrected this in my reply above, see this
if( g_form.getValue('u_activity')== ''){ // this if was wrong
return false; //Abort submission
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 08:07 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 08:12 AM
thanks!
But im getting an error from line 8:
not sure what is this condition??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 08:14 AM
I corrected this in my reply above, see this
if( g_form.getValue('u_activity')== ''){ // this if was wrong
return false; //Abort submission
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 11:54 PM
Many thanks Anurag!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2024 08:16 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader