Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Ui page from OnSubmit client script

hugogomes
Giga Expert

Hi community,

I'm trying to create a functionality to force users to add close notes when changing the state of a sc_task to "closed".

I have created a Client script with the following code:

function onSubmit() {

    var state = g_form.getValue('state');

if (state === '3'){

   

var close_note = g_form.getValue("close_notes");

var short_text = g_form.getValue("short_description");

var dialog = new GlideDialogWindow("enter_close_notes");

dialog.setTitle("Please enter Close Notes");

dialog.setPreference("close_note", close_note);

dialog.setPreference("short_text", short_text);

dialog.render();

}

}

It calls an Ui page:

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

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

<g:ui_form>

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

  <g:evaluate var="jvar_short_text"

      expression="RP.getWindowProperties().get('short_text')" />

  <g:evaluate var="jvar_close_note"

      expression="RP.getWindowProperties().get('close_note')" />

    <!-- Set up form fields and labels -->

    <table width="100%">

        <tr id="description_row" valign="top">

              <td colspan="2">

                    <!-- Short description value used as a label -->

                    ${jvar_short_text}

              </td>

        </tr>

        <tr>

            <td align="left">

                <!-- Comments text field (Contains comments from originating record as a default) -->

                <g:ui_multiline_input_field name="dialog_close_note" id="dialog_close_note" label="Close Notes"

                      value="${jvar_close_note}" mandatory="true" />

            </td>

        </tr>

        <tr>

            <td colspan="2">

            </td>

        </tr>

        <tr id="dialog_buttons">

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

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

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

              </td>

        </tr>

  </table>

</g:ui_form>

</j:jelly>

Client script:

function validateCloseNotes() {

var close_note = gel("dialog_close_note").value;

close_note = trim(close_note);

if (close_note === "") {

alert("Please enter your Close Notes before submitting.");

return false;

}

GlideDialogWindow.get().destroy();

g_form.setValue("close_notes", close_note);

g_form.setValue("work_notes", "Close Notes: " + close_note);

g_form.update();

return true;

}

The problem here is, after pressing "OK" nothing happens, it doesn't save the record.

I have checked other posts and it seems that some users had the same problem but I didn't figure out, from their problems, how to solve mine.

Any ideas?

Thank you in advance

1 ACCEPTED SOLUTION

hugogomes
Giga Expert

Found a solution for this



I have changed the client script where I call the Ui Page to this:



function onSubmit() {


    var state = g_form.getValue('state');


var closenotes = g_form.getValue('close_notes');


if (state === '3' && closenotes === ''){


   


var close_note = g_form.getValue("close_notes");


var short_text = g_form.getValue("short_description");




var dialog = new GlideDialogWindow("enter_close_notes");


dialog.setTitle("Please enter Close Notes");


dialog.setPreference("close_note", close_note);


dialog.setPreference("short_text", short_text);


dialog.render();



}


if (closenotes === ''){


return false;


}


}



Working fine!



Thank you for your help!


View solution in original post

7 REPLIES 7

Ravish Shetty
Tera Guru

Line 15: Use g_form.save() instead.


Not sure if that will help.


Hi, thank you for your help.



I have tried that, but it doesn't work either.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Hugo Gomes wrote:



Hi community,



I'm trying to create a functionality to force users to add close notes when changing the state of a sc_task to "closed".


Have you looked at how it's done for an incident record?


For Incident we use Ui Policy.



But for sc_task is different, because we don't use the field, "close notes". So I need to "force" users to insert a value in that field, that will also be in work notes.