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 and ui action to update work_start and work_end on change request form when closing

Casper Gr_nborg
Tera Contributor

Hi all.

 

Hopefully somebody can help me in the right direction 🙂

I would like to create an ui page as pop up based on ui action - when a change request is closed.

 

The requirement is to writeback to "work_start" and "work_end" from the ui page,

and then redirect to the edited record.

 

I have looked into many tutorials and guides, but have not been able to get it correct yet.

 

UI Action:

 

function loadConfirmDialog() {
    //Initialize and open the Dialog Window
var dialog = new GlideDialogWindow("U_Change_actual_date");
dialog.setPreference("sysparm_id", g_form.getUniqueValue());
dialog.setPreference("sysparm_number", g_form.getValue('number'));
dialog.render();
}
 
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 id="f_id">

        <input type="hidden" id="sys_id" name="sys_id" value="${sysparm_id}"/>
        <input type="hidden" id="number" name="number" value="${sysparm_number}"/>
        <input type="hidden" id="item" name="item" value="${sysparm_id}"/>
            <center><h2>Close Change Request</h2>
                <table>
                    <tr>
                        <td>Change Request:</td>
                        <td>
                            <g:ui_reference name="change_request" table="change_request" field="number" id="change_request" displayvalue="${sysparm_number}" value="${sysparm_id}"/>
                        </td>
                    </tr>
                    <tr>
                        <td>Work Start Date:</td>
                        <td><g:ui_date_time name="work_start" id="work_start" value=""/></td> <!-- Use g:ui_date for Work Start Date -->
                    </tr>
                    <tr>
                        <td>Work End Date:</td>
                        <td><g:ui_date_time name="work_end" id="work_end" value=""/></td> <!-- Use g:ui_date for Work End Date -->
                    </tr>

                    <tr>
                        <td colspan="2">
                            <div style="text-align: center;">
                                <input type="submit" value="Submit" onClick="submitForm()"/>
                                <input type="button" value="Cancel" onClick="cancelForm()"/>
                            </div>
                        </td>
                    </tr>
                </table>
            </center>
        </g:ui_form>
</j:jelly>
 
Client Script:
function cancelForm() {
window.close();

}
 
Processing script:
 
var chg = new GlideRecord('change_request');
chg.addQuery('sys_id', sys_id);
chg.initialize();
chg.start_date = work_start;
chg.end_date = work_end;
chg.update();
var URL = "https://xxxxxx.service-now.com/change_request.do?sys_id=" + sys_id; // URL of newly created incident record
response.sendRedirect(URL); //sendRedirect() method redirects the response to another resource, inside or outside the server.
 
 
0 REPLIES 0