Confirm popup on submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2017 03:53 PM
Hello experts,
So I'm trying to get a confirmation pop up to work onSubmit off a referenced field in a SCOPED APP. I want to say get the display value from the 'source' field and put it in the confirm box. I've checked to make sure the display is 'true' for 'name' on source table. trying this following code, but not working for me.
If I do getValue('source'), then I get a sysid back, so that tells me since it's a reference, I need to dot walk it. But can't seem to figure it out. Please help! Thanks.
function onSubmit() {
var source = g_form.getDisplayValue('source.name');
var confirm = confirm("Are you sure "+ source + " is correct?");
if (confirm == false){
return false;
}
}
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2017 06:53 PM
Hi Kim,
Please try the below script and let me know. I have tested similar functionality in my personal instance and that us working fine.
function onSubmit() {
var src = g_form.getReference('source', getName); //Referring the table using the callback function
function getName(src){
var value = src.name; //This will store the value of the 'name' field available in the referred table referred by 'source' field
var con = confirm("Are you sure "+ value + " is correct?");
if(con == true)
//do nothing
if(con == false)
return false;
}
}
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2017 07:01 PM
Doesn't using a callback make it asynchronous, which shouldn't be working for onSubmit because the form submits before waiting for the return?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2017 02:44 AM
Correct you are. in onSubmit Client Script we can not use asynchronous function. If it would not be an issue of Scoped Application, then we could have used synchronous GlideAjax by using getXMLWait(), refer here Examples of asynchronous GlideAjax.
Again getXMLWait() is not applicable in Scoped application. There is similar discussion took place in this thread, Access to getXMLWait is not available in scoped applications , what is workaround ?, where HI Team has provided an workaround. kimj2942 can go ahead and opt that option in this case.
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2017 07:17 PM
Because this is a client script and a scoped app, you are going to have to do a couple things. You do not have access to the server side GlideRecord calls, and you are limited to the scoped API calls. Also, callbacks shouldn't be working because it makes an asynchronous (GlideAjax) call and form will submit before waiting for the return.
First. the reference table, is it set up to allow select from all application scopes?
The getDisplayValue call is a server GlideRecord call so won't work here. Also it looks like getDisplayBox is only allowed from global scoped scripts.
Try this, it will block UI but not sure what other option there is:
function onSubmit() {
var source = g_form.getReference('source'); //The source in quotes should be your reference field name
var confirm = confirm("Are you sure "+ source.name + " is correct?");
if (confirm == false) {
return false;
}
}