- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 05:21 AM - edited 03-31-2025 05:26 AM
I'm looking to use a confirm pop up box on a UI Action, but would prefer it if the confirm pop up box only appeared on condition of a dot-walked field value not being empty, and otherwise execute a basic save. The UI Action currently stands like the below, and works fine.... the confirm pop up box is triggered and if Yes is clicked then the later if statement is executed. If no is clicked then an alert pops up to say the form hasn't been saved.
This works fine but is triggered every time the UI Action is clicked:
function confirmChangeSubmission() {
var answer = confirm('This will save the change, are you sure?');
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
} else {
alert('The form has not been saved');
}
}
if (typeof window == 'undefined') {
current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
I've tried variations on the following with an if statement in the initial function called by the onClick but when clicked the form does nothing... understandably because it's a client script being asked to do a server query:
function confirmChangeSubmission() {
if (current.company.u_change_leadtime != '') {
var answer = confirm('This will save the change, are you sure?');
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
} else {
alert('The form has not been saved');
}
} else {
current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
}
if (typeof window == 'undefined') {
current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
However, I'd prefer it if the popup box only appeared if the dot-walked field (company.u_change_leadtime) on the form was not empty. Is that possible, and if so, how?
Thanks in advance for any insight on this. The only other option I can think of is to use different UI Actions to only show according to the value as the form is saved, but that would be far less graceful and far less reliable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 05:33 AM
you cannot dot walk like that in client side of UI action
You can use getReference with callback and check the value of dot walked field
function confirmChangeSubmission() {
var ref = g_form.getReference('company', callBackMethod);
function callBackMethod(ref) {
if (ref.u_change_leadtime != '') {
var answer = confirm('This will save the change, are you sure?');
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
} else {
alert('The form has not been saved');
}
} else {
// field is empty so no confirm directly server side
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
}
}
}
if (typeof window == 'undefined') {
current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 05:33 AM
you cannot dot walk like that in client side of UI action
You can use getReference with callback and check the value of dot walked field
function confirmChangeSubmission() {
var ref = g_form.getReference('company', callBackMethod);
function callBackMethod(ref) {
if (ref.u_change_leadtime != '') {
var answer = confirm('This will save the change, are you sure?');
if (answer) {
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
} else {
alert('The form has not been saved');
}
} else {
// field is empty so no confirm directly server side
gsftSubmit(null, g_form.getFormElement(), 'sysverb_insert_and_stay');
}
}
}
if (typeof window == 'undefined') {
current.insert();
action.setRedirectURL(current);
gs.include('ActionUtils');
var au = new ActionUtils();
au.postInsert(current);
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 05:44 AM
Thanks @Ankur Bawiskar , that's awesome... just tested it and it works.
I was starting to wonder if I'd have to create a new UI page or some other more complicated and complex solution, but that's really graceful and one I'll be adding to my personal 'cheat sheet' for future. Thanks again, hope you have a great week. 😁
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 05:50 AM
Glad to help
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader