- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 04:49 AM - edited 02-06-2024 04:49 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 06:01 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 04:56 AM
Hi @gunishi ,
I heavily recommend you to check this article first (especially the 3 videos).
Regards, Ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 04:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 05:05 AM
what's your business requirement here?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 05:08 AM
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