UI Page not running processing script

grosch
Mega Expert

In my UI Page I've stuck this line to create the ok and cancel buttons:

<g:dialog_buttons_ok_cancel ok="return makeChanges()" ok_type="button" cancel_type="button" />

I then have this in the client script window:

function makeChanges() {

      var service = gel("service").value;

      if (!service) {

              alert("Please select a service to update.");

              return false;

      }

      GlideDialogWindow.get().destroy(); //Close the dialog window

      return true;

}

When I hit OK, the window just goes away.   The code that I have in the Processing script never runs.   Is it because I listed an "ok" callback?   Basically I need to make sure the input is OK and then if it is do the work server side.

16 REPLIES 16

manikorada
ServiceNow Employee
ServiceNow Employee

Scott,



Can you copy the entire UI Page HTML?


<g:ui_form>


  <!-- Get the values from dialog preferences -->


  <g:evaluate var="jvar_model_sys_id" expression="RP.getWindowProperties().get('model_sys_id')" />


  <g:evaluate var="jvar_model_name" expression="RP.getWindowProperties().get('model_name')" />


  <g:evaluate var="jvar_class_name" expression="RP.getWindowProperties().get('class_name')" />


  <g:evaluate var="jvar_services">


      var gr = new GlideAggregate('u_user_membership');


      gr.addQuery('u_user.sys_id', gs.getUserID());


      gr.addQuery('u_role.name', 'Asset ${AMP} Configuration Manager');


      gr.addNotNullQuery('u_service');


      gr.groupBy('u_service');


      gr.query();




      var services = [];


      while (gr.next()) {


      services.push(gr.u_service.sys_id.toString());


      }


      gr.close();




      services.join();


  </g:evaluate>


  <g:evaluate var="jvar_service_query" jelly="true">


      'u_state=Active^u_support_service.sys_idIN' + jelly.jvar_services;


  </g:evaluate>




  <p>


      Pressing OK will update$[SP]<strong>every</strong>$[SP]hardware asset


      <j:if test="${jvar_services.indexOf(',') == -1}">in your service</j:if>


      <j:if test="${jvar_services.indexOf(',') != -1}">for the service you select, below,</j:if>


      which has the model ${jvar_model_name} to have the class ${jvar_class_name}.


  </p>




  <table width="100%">


      <j:if test="${jvar_services.indexOf(',') != -1}">


          <tr>


              <th>Service To Update:</th>


              <td>


                  <g:ui_reference name="service" table="cmdb_ci_service" query="${jvar_service_query}"/>


              </td>


          </tr>


          <tr>


              <td colspan="2">


              </td>


          </tr>


      </j:if>


      <tr id="dialog_buttons">


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


              <!-- Add OK/Cancel buttons. Clicking OK calls the validateComments script -->


              <g:dialog_buttons_ok_cancel ok="return makeChanges()" ok_type="button" cancel_type="button" />


          </td>


      </tr>


  </table>


  <input type="hidden" name="modelSysId" value="${jvar_model_sys_id}" />


</g:ui_form>


Hi Scott,


                        Make this two changes then it should work.


      • Call your client script function in <g:ui_form> tag like <g:ui_form onsubmit="return makeChanges();">
      • Change ok_type to submit like ok_type="submit.

                          It worked for me Let me know if you have any problems after this changes.


Thanks,


Sai.


Dude this thing actually worked! The key is for the processing script to work the form needs to get submitted.  



Processing ScriptThis script runs on the server when the page is submitted. This is mainly useful if your page has a form (defined with the <g:ui_form/> or <g:form/> tags).


If your UI Page contains a form (uses the <g:form> tag), you can submit the form and have the Process Script run.


The above words from the official documentation.   So once I changed the ok_type in


              <g:dialog_buttons_ok_cancel ok="return makeChanges()" ok_type="button" cancel_type="button" />



to ok_type="submit".     The processing script happily ran! Thankyou!