The CreatorCon Call for Content is officially open! Get started here.

How to use UI Page in OnSubmit client script

Supriya25
Tera Guru

Hi All,

Please help me on below issue

How to validate  UI Page value in Onsubmit

 

OnSubmit:

function onSubmit() {

if (g_form.getActionName() == "resolve_incident") {
var gm = new GlideModal('confirm_changes');
gm.setTitle('Confirm');
gm.setWidth(400);
gm.render();

 

image.png


if(user clicked on 'Do Change' button )
{
g_form.setReadonly('field 1',false);
g_form.setReadonly('field 2',false);

g_form.addErrorMessage("Change values on fields");

return false;
}

if(user clicked on 'Confirmed' button)

{

validateDates();

return true;

}

function checkManagers()

{

if(........)

{

return false;

}else{

return true;

}

}return true;
}
}

}

Supriya25_0-1673872105865.png

 

 

HTMl :

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<p>Are you sure about your changes ?</p>

<br/>

<div style="float: right">

<g:dialog_buttons_ok_cancel ok="return sendvalue()" ok_type="button" ok_text="Confirmed" ok_style_class="btn btn-primary" cancel="return destroyWindow()" cancel_type="button" cancel_text="Do Change" cancel_style_class="btn btn-default" />

</div>

</j:jelly>

 

Client script :

function sendvalue {

    destroyWindow();

    return true;

}

function destroyWindow() {

    GlideDialogWindow.get().destroy();

    return false;

}

 

 

 

13 REPLIES 13

Omkar Kumbhar
Mega Sage

Hello @Supriya25 ,

Please find the below link. Let me know if this hekps you.

https://www.servicenow.com/community/developer-forum/ui-page-from-onsubmit-client-script/m-p/1540694

 

Thanks,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Omkar Kumbhar
Mega Sage

Hello @Supriya25 ,

Please find the below code modification in ui page.

OmkarKumbhar_0-1673880590688.png

 

You can use 

g_form.setReadOnly(field1,true);

g_form.setReadOnly(field2,true);

g_form.save 

in UI page itself it is working for me you can try and let me know.

 

Thanks,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

Omkar Kumbhar
Mega Sage

Hello @Supriya25 ,

Please find the client script. Please uncheck the isolate script checkbox.

OmkarKumbhar_0-1673890555647.png

 

function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getActionName() == "resolve_incident") {
//function confirmDialog(){
var gm = new GlideModal('confirm');
//Sets the dialog title
gm.setTitle('Confirmation');
//Set up valid custom HTML to be displayed
gm.renderWithContent('\
<div style="padding:15px"><p>Confirm?</p>\
<div style="padding:5px;float:right">\
<button style="padding:5px;margin-right:10px" \
onclick="window.takeAction(this.innerHTML)" \
class="btn btn-default">Do Change</button>\
<button style="padding:5px" \
onclick="window.takeAction(this.innerHTML)" \
class="btn btn-primary">Confirmed</button>\
</div> \
</div>');

//We'll use the windows object to ensure our code is accessible from the modal dialog
window.takeAction = function(thisButton){

//Close the glide modal dialog window when either button is pressed.
gm.destroy();

//perform the appropriate action on the client.
if(thisButton=='Confirmed'){
g_form.addInfoMessage('Incident is resolved successfully'); // modify this 29 and 30 line accodin to your requirement
g_form.save();

} else if(thisButton=='Do Change') {
g_form.addErrorMessage('Please carry out changes');
gm.destroy();
}
};
return false;//prevents the form from submitting when the dialog first loads
}
}

 

Thanks,

Omkar

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

@Supriya25 no need to create a UI page

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.