UI action Alert to fill "Comments" field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 02:32 AM
I have a record producer , where I have a "Reject" Button . When I click on Reject the "status " field changes to "Rejected" . requirement is to add a validation , if "comments" field is empty then It will not change the state and there will be an alert saying "please enter the reason in comments field".
Below is my code which doesn't work .
if(g_form.getValue ('u_comments') == "")
{
gs.addErrorMessage('please enter the reason in comments field' );
action.setRedirectURL(current);
}
else {
current.u_state="Rejected";
current.update();
gs.addInfoMessage('You have Rejected the Request' );
action.setRedirectURL(current);
}
I have also tried if(current.u_comments== "") that didn't work too .
Please help me on this
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 03:33 AM
Hi there,
Try out this one...
if(g_form.getValue ('u_comments') == ''){
gs.addErrorMessage('please enter the reason in comments field' );
return false; //this will abort the action
}
Mark it correct if worked for u as well so that it will be helpful to others as well
Regards,
Snehal M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 04:23 AM
Hello,
You can add a before update business rule for this scenario just as how it works OOB.
There is an OOB business rule which does the same on Approval table, Please refer to "Make comments required" on sysapproval_approver table.
URL: Replace your instance_name
Condition: State changes to Rejected
Condition String: current.comments.nil()
Script:
(function executeRule(current, previous /*null when async*/) {
gs.addErrorMessage(gs.getMessage('please enter the reason in comments field'));
current.setAbortAction(true);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 09:41 PM
Hi,
Try with the below script in UI action.
Do the following configuration:
Client checkbox: unchecked
Form Button: Checked
if(current.description.nil()) // put you field name instead of description
{
gs.addErrorMessage(gs.getMessage('please enter the reason in comments field'));
current.setAbortAction(true);
action.setRedirectURL(current);
}
else
{
current.state = '6'; // put backend value of choice you want to set
current.update();
action.setRedirectURL(current);
}
Mark Correct/Helpful, if this helps you.
Regards,
Devyani