- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 09:22 AM
Hello SN Community!
I'm trying to script a UI action. Basically we have a user clicking the UI Action to check mandatory fields and send for approval. The script looks like this:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 09:26 AM - edited 05-14-2024 09:28 AM
Hi,
Try this. This will check one field at a time and only add the error on one.
if (current.field1 == '') {
gs.addInfoMessage("Please populate Field 1.");
action.setRedirectURL(current);
}
else if (current.field2 == '') {
gs.addInfoMessage("Please populate Field 2.");
action.setRedirectURL(current);
}
else if (current.field3 == '') {
gs.addInfoMessage("Please populate Field 3.");
action.setRedirectURL(current);
}
else if (current.field4 == '') {
gs.addInfoMessage("Please populate Field 4.");
action.setRedirectURL(current);
} else {
gs.addInfoMessage("Record sent for approval.");
current.status = '8';
current.update();
action.setRedirectURL(current);
}
If you want to check all blank fields and add all messages then try this
if (current.field1 == '') {
gs.addInfoMessage("Please populate Field 1.");
}
if (current.field2 == '') {
gs.addInfoMessage("Please populate Field 2.");
}
if (current.field3 == '') {
gs.addInfoMessage("Please populate Field 3.");
}
if (current.field4 == '') {
gs.addInfoMessage("Please populate Field 4.");
} else {
gs.addInfoMessage("Record sent for approval.");
current.status = '8';
current.update();
action.setRedirectURL(current);
}
action.setRedirectURL(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 12:08 PM
That makes sense. You can use UI policies to only make those fields mandatory when they are not in a draft state.
In the example below, the On Hold Reason field is only mandatory when the state is On Hold. You can use this same method but change the criteria to is no Draft to get the result you're looking for.