Explaining an OOTB UI page

gunishi
Tera Guru

Hi there, 

 

Could someone please provide a line-by-line explanation for this code? I am new to jelly scripting and XML and am trying to recreate something similar for my requirements. 

 

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

<g:dialog_notes_ok_cancel dialog_id="change_confirm_cancel"

textarea_id="change_confirm_reason_text"

textarea_label="${gs.getMessage('Reason')}"

textarea_label_title="${gs.getMessage('A reason is required to cancel this change')}"

textarea_name="change_confirm_reason_text"

textarea_onkeyup="enableButton()"

textarea_onchange="enableButton()"

textarea_style="height:auto; width: 100%; resize: vertical;"

textarea_title="${gs.getMessage('Enter the reason here')}"

ok=""

ok_action="cancelChangeRequest"

ok_id="change_confirm_ok_btn"

ok_title="${gs.getMessage('Cancel change request')}"

ok_type="button"

ok_style_class="btn btn-primary disabled"

cancel_title="${gs.getMessage('Close the dialog')}"

/>

</j:jelly>

 

Client script:
function cancelChangeRequest() {

    var textArea = $("change_confirm_reason_text");

    if (textArea)

         moveToCancel(textArea.value.trim());

}

(function() {

    $("change_confirm_reason_text").focus();

})();

 

Many thanks in advance,

G

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

HTML/XML:

<!-- This first line declares what type of document it is. It is similar to the DOCTYPE for an html page-->
<?xml version="1.0" encoding="utf-8" ?>

<!-- This is the initial jelly tag to tell the system that everything in between may have some jelly code and it sets up namespacing-->
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<!-- this is actually one line of code. It's a jelly tag that is calling a UI Macro by the name of dialog_notes_ok_cancel. All the attributes on this tag are accepting parameters/values to be placed into the script that this tag brings in. After taking in the inputs it will render what the dialog_notes_ok_cancel macro contains-->
<g:dialog_notes_ok_cancel dialog_id="change_confirm_cancel"

textarea_id="change_confirm_reason_text"

textarea_label="${gs.getMessage('Reason')}"

textarea_label_title="${gs.getMessage('A reason is required to cancel this change')}"

textarea_name="change_confirm_reason_text"

textarea_onkeyup="enableButton()"

textarea_onchange="enableButton()"

textarea_style="height:auto; width: 100%; resize: vertical;"

textarea_title="${gs.getMessage('Enter the reason here')}"

ok=""

ok_action="cancelChangeRequest"

ok_id="change_confirm_ok_btn"

ok_title="${gs.getMessage('Cancel change request')}"

ok_type="button"

ok_style_class="btn btn-primary disabled"

cancel_title="${gs.getMessage('Close the dialog')}"

/>
<!-- The end of the dialog_notes_ok_cancel tag-->

</j:jelly>



 

 

Client Script:

// A function that will execute when the OK button is clicked
function cancelChangeRequest() {

    var textArea = $("change_confirm_reason_text");

    if (textArea)

         moveToCancel(textArea.value.trim());

}

// an IIFE that puts the focus on the change_confirm_reason_text textarea element
(function() {

    $("change_confirm_reason_text").focus();

})();

 

You can find the UI Macro within your ServiceNow platform
ui_macro.png

View solution in original post

9 REPLIES 9

Ivan Betev
Mega Sage
Mega Sage

Hi @gunishi ,

 

I heavily recommend you to check this article first (especially the 3 videos).

 

Jelly tags (servicenow.com)

 

Regards, Ivan

Hi @Ivan Betev 

 

Thank you for this, I didn't know about this resource.

 

Kind regards, 

G

Ankur Bawiskar
Tera Patron
Tera Patron

@gunishi 

what's your business requirement here?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

I have a requirement where I have a 'cancel reason' field on a form. I would like a popup when the user clicks on the 'cancel' button, and for a pop-up to appear asking for a cancellation reason (maybe a dialogue box). Once the user types in the reason and presses 'ok' I want it to populate the 'cancel reason' field on the form. 

 

I am very new to this though so any support would be much appreciated. 

 

Kind regards, 

G