- 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 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 10:08 AM
Ah, the else ifs worked perfectly, thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 09:30 AM
Hi Ishenferi,
Are these fields already flagged as mandatory?
If not, you could use a UI policy instead to make these mandatory instead of checking this in your UI action.
Thank you,
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 10:08 AM
The issue was they want no mandatory fields in a Draft state, and only when clicking the UI Action do they become mandatory.