How to submit UI page form using script

Jim J1
Tera Guru

What is best practice to submit a UI page form from a client script

1 ACCEPTED SOLUTION

Jim J1
Tera Guru

Trace issue to g:dialog_buttons_ok_cancel having extra attributes, e.g. 'ok_type=button'

View solution in original post

7 REPLIES 7

Harsh Vardhan
Giga Patron

can you add more details about your requirement ? 

if possible add some example and screenshot 

Jim J1
Tera Guru

Here's the code.

It only works correctly in IE and does not work in firefox, chrome or edge. On submit does not trigger the  processing script.

It was created several years ago and stopped functioning with our upgrade to New York

 

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">

 

<g2:evaluate var="jvar_jobname">

   var jobname = RP.getParameterValue('sysparm_jobname');

   jobname;

</g2:evaluate>

<g:ui_form>

<form id="mytest" name="mytest" method="post">

<table width="100%">

        <tr><td/><td/></tr>

        <g:evaluate>

                var title = "${RP.getWindowProperties().get('title')}";

                title =  new GlideStringUtil().unEscapeHTML(title);

        </g:evaluate>

 

               <tr>

               <td nowrap="true"><g:no_escape>${title}</g:no_escape></td>  

               </tr>

        <tr><td/><br/><td/></tr>

        <tr>

            <td colspan="2" align="right">

                <g:dialog_buttons_ok_cancel

                   ok="invokeSubmitCall('ok');"

                   ok_type="button"

                   cancel="invokeSubmitCall('cancel')"

                   cancel_type="button" />

            </td>

        </tr>            

</table>

              

               <input type="HIDDEN" name="jobname" id="jobname" value="$[jvar_jobname]" />

               <button type="SUBMIT" id="submitform" name="SubmitForm" value="Submit" style="display: none" />

               </form>             

                             

</g:ui_form>

 

Client script

function invokeSubmitCall(type) {

    var gdw = GlideDialogWindow.get();

               var nameofjob = gel('jobname');

    if (type == 'ok') {

                             

                 gel("submitform").click();

                 window.location = window.location;

                 GlideUI.get().display({text:'Load for '+nameofjob.value+' Successfully Submitted!',type:'',sticky:false,closeDelay:5000,bundleMessages:false});

                                            

               }

              

    gdw.destroy();

    return false;

}

Processing script

//Execute a scheduled script job

/ for tersting 

gs.log("BOOM TESTING ASN LOAD Fired");

 

 

Your best bet is to set a value on a hidden input field in the HTML section to submit (for example) from the Client Script section and let the Processing script do the work. This is supported in all browsers and ServiceNow have been doing it this way for many, many years.

 

Hope that helps

this should work. are you getting any error in console?