How to popup free text field when we click on UI action button?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 06:15 AM
I want to popup free text field as " Justification " once we click on UI action button and then those justification comments should be updated in the worknotes after that.
Can anyone have an idea on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 05:01 PM
I've actually attempted this before just to test things out for another community question. You can call a modal object to display the current form but with specified fields via a custom view.
function testMe(){
//var gm = new GlideModalForm('dialog title', 'table_name_or_form_name', [callback on completion of submit]);
var gm = new GlideModalForm("JUSTIFICATION REQUIRED", "incident", finishRunning);
gm.setSysID(g_form.getUniqueValue()); //<--Get the current record
gm.addParm('sysparm_view', 'assess_dialog_form_view'); //<--Custom form view name, this could just have the work notes field and be a mandatory field in this view
gm.render();
function finishRunning(){
//do something after if needed;
}
}
Outside of the above method, you could create a UI Page for the modal. I think a UI Page takes a bit more work though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:54 AM
Hi Suresh,
To achieve this you have to create ui page where you will add Justification as input string field.
And call this ui page in your ui action .
If my answer helped you to get you query resolved Mark it helpful.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 12:15 PM
Hello @Suresh56,
Here are the steps you need to follow:
- First, you need to create a UI page that contains the free text field and a submit button. You can use the GlideDialogWindow class to create a custom popup window that displays the UI page. You can also use the setPreference method to pass parameters from the UI action to the UI page, such as the sys_id of the current record.
- Second, you need to create a client script for the UI page that handles the submit button click event. You can use the getPreference method to get the parameters passed from the UI action, such as the sys_id of the current record. You can also use the getValue method to get the text entered in the free text field. Then, you can use the GlideAjax class to call a script include that updates the worknotes of the current record with the text.
- Third, you need to create a script include that contains the logic for updating the worknotes of the current record. You can use the [GlideRecord] class to query and update the record by its sys_id. You can also use the [setWorkNotes] method to append the text to the worknotes field.
I have tried to put some script
UI Action
//Get the sys_id of the current record
var sys_id = g_form.getUniqueValue();
//Create a GlideDialogWindow object
var dialog = new GlideDialogWindow(‘justification_dialog’);
//Set the title of the dialog
dialog.setTitle(‘Enter Justification’);
//Set the size of the dialog
dialog.setSize(400, 200);
//Pass the sys_id as a preference to the dialog
dialog.setPreference(‘sysparm_sys_id’, sys_id);
//Render the dialog
dialog.render();
UI Page
//Get the sys_id from the preference
var sys_id = getPreference(‘sysparm_sys_id’);
//Get the free text field element
var justification = document.getElementById(‘justification’);
//Get the submit button element
var submit = document.getElementById(‘submit’);
//Add a click event listener to the submit button
submit.addEventListener(‘click’, function () {
//Get the text entered in the free text field
var text = justification.value;
//Check if the text is not empty
if (text) {
//Create a GlideAjax object
var ga = new GlideAjax(‘UpdateWorknotes’);
//Pass the sys_id and the text as parameters
ga.addParam(‘sysparm_name’, ‘updateWorknotes’);
ga.addParam(‘sysparm_sys_id’, sys_id);
ga.addParam(‘sysparm_text’, text);
//Call the script include and get the response
ga.getXML(function (response) {
//Get the result from the response
var result = response.responseXML.documentElement.getAttribute(“answer”);
//Check if the result is true
if (result == ‘true’) {
//Close the dialog window
GlideDialogWindow.get().destroy();
//Refresh the form
g_form.refresh();
} else {
//Show an error message
alert(‘Failed to update worknotes’);
}
});
} else {
//Show a warning message
alert(‘Please enter some justification’);
}
});
Script Include
var UpdateWorknotes = Class.create();
UpdateWorknotes.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateWorknotes: function () {
//Get the sys_id and the text from the parameters
var sys_id = this.getParameter(‘sysparm_sys_id’);
var text = this.getParameter(‘sysparm_text’);
//Create a GlideRecord object for the table that contains the record
var gr = new GlideRecord(‘table_name’);
//Query for the record by its sys_id
gr.get(sys_id);
//Set the worknotes with the text
gr.setWorkNotes(text);
//Update the record and return true or false depending on the success
return gr.update();
},
type: ‘UpdateWorknotes’
});
Hope this helps.
Kind Regards,
Swarnadeep Nandy