asifnoor
Kilo Patron

Hi,

In this article, I will show you how you can create a custom UI page in ServiceNow and call that in a popup.

For this, first we need to create a  UI Page.

System UI -> UI Pages -> New

UI Page Name: ui_page_demo

HTML Script

<?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>
	<table>
		<tr>
		<td style="width:25%">
			<g:form_label>
			Name: 
			</g:form_label>
                 </td>
		<td style="width:60%"> 
                 <input type="text" aria-label="Print your name" name="my_name" id="my_name" maxlength="25"/>	
                </td>
		</tr>
		<tr>
                  <td style="width:25%">
			<g:form_label>
			Select User: 
		        </g:form_label>		
                  </td>
		  <td style="width:60%">
		    <g:ui_reference name="user_ref" id="user_ref" query="user_nameSTARTSWITHa" table="sys_user"  />
                   </td>
                </tr>
		<tr>
                   <td style="width:25%">
			<g:form_label>
			Select Incident: 
			</g:form_label>
                   </td>
		    <td style="width:60%">
                      <g:ui_choicelist name="my_category" id="my_category" table="incident" mandatory="true"   field="category" query="active=true"/>
                    </td>
                </tr>
		<tr>
                     <td>
                       <g:dialog_buttons_ok_cancel ok_id="submitData" ok="return continueOK()" ok_type="button" ok_text="${gs.getMessage('Okay')}" ok_style_class="btn btn-primary" cancel_type="button" cancel_id="cancelData" cancel_style_class="btn btn-default" cancel="return continueCancel()"/>
                    </td>
               </tr>
	</table>
	</g:ui_form>
</j:jelly>

Client Script

function continueOK() {
	alert("OK clicked");
	var gdw = GlideDialogWindow.get();
	var name =gel('my_name').value;
	var user = gel('user_ref').value;
	var cat = gel('my_category').value;
        var sys_id = gdw.getPreference('sys_id'); //get the values passed in the client script 
	var selected_value = gdw.getPreference('value'); //get the values passed in the client script 
	alert(name+"---"+user+"---"+cat+"---"+sys_id+"---"+selected_value);
	GlideDialogWindow.get().destroy();
}
function continueCancel() {
	alert("Cancel clicked");
	GlideDialogWindow.get().destroy();
}

Processing Script

This will be useful if you are calling a UI page directly (instead of popup) and have a html form. Then all the submitted values of the form can be captured in the processing script like below.  Do note that the processing scripts contains server side code and you can store the values in the table or do any other server actions from there.

var user = request.getParameter("user_ref"); //mention the name of the elment here
var my_name = request.getParameter("my_name"); //mention the name of the elment here
var category = request.getParameter("my_category"); //mention the name of the elment here
gs.info("Asif: testing "+user+"---"+my_name+"---"+category);
//you can do gliderecord and store or add any other server side code here

 

Once this is done, save this.

Now you can call this UI action in a popup from any client script. In our example, i am written this onChange client script of 1 field in incident form.

onChange Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var dialog = new GlideDialogWindow('ui_page_demo'); //Mention your UI Page name here
    dialog.setTitle('UI Page Demo'); //Set the dialog title
    dialog.setSize(650, 600); //Set the dialog size
    dialog.setPreference('sys_id', g_form.getUniqueValue()); //pass current object id
    dialog.setPreference('value',newValue);//pass the selected value on the form	
    dialog.render(); //Open the dialog   
}

 

Output

find_real_file.png

Let me know if you have any questions in the comments below.

Mark the article as helpful and bookmark if you found it useful.


Regards,
Asif
2020 ServiceNow Community MVP

 

Comments
viraj4
Giga Contributor

Hi Asif,

Thanks for the article its quite useful.

Regards,

Viraj

Jerome11
Tera Guru

Hi Asif,

Can you provide an example where the pop-up selects from field type = Table Name instead of reference to User table?

Thanks,

- Jerome

 

asifnoor
Kilo Patron

Did not understand what you meant by that. Can you explain a little more with an example.

Jerome11
Tera Guru

Asif,

Your example showed selecting a user from a reference field. I would like to know if the same thing is possible for a field type = Table Name.

 

E.g., see field "Creates" on this form: 

https://devxxxxx.service-now.com/nav_to.do?uri=cmdb_ip_service.do?sys_id=db9840e10ab3015500f5e3fe8f78da42

 

find_real_file.png

asifnoor
Kilo Patron

Hi,

There are only 3 components (jelly tags) supported by ServiceNow which are input field, checkbox and reference along with ok_cancel buttons. 

For the kind of example you shown you might have to first fetch the options in a array and then use basic html dropdown and update the values in that.

https://docs.servicenow.com/bundle/paris-application-development/page/script/general-scripting/conce...

Mark the article and comment as helpful if it helps.

Onkar Pandav
Tera Guru

Thank you Asif for providing this.

Just one question here.
How can we show choice list value as it is. If I want to show form field values (record is already created) then how can we show the choice list value.

For eg. there are two fields, reference & choice list. In a reference field there is a value "Abc" and choice list has option "Mumbai" selected, then if I click on UI action then UI page should be displayed with two those two fields and also the values in it (like Abc and Mumbai).

Please guide me on this @asifnoor .

asifnoor
Kilo Patron

In the UI page, do you wnat those to be changed. or just show them in plain text fields?

Onkar Pandav
Tera Guru

Yes, user should be able to change it as well.

josenava
Tera Expert

Hello Asifnoor, I have a question, I created a UI action to create a new task, this UI action is in the RITM form:

find_real_file.png

the idea is that when the user clicks on the UI action, the pop up window shows up, I made some modifications to the UI page which is this one:

find_real_file.png

how can I get the information from  the pop up window copied to the new task created from the ui action? so when the user clicks on Submit, the new task is created with their information added, and if the user clicks on Cancel, nothing happens, and the user remains in the same page.

Thank you

VIshnu65
Tera Contributor

Could you please provide the code for that ui action

asifnoor
Kilo Patron

Hi,

In the client script, you get the values and you can use GlideAjax and can do further processing.

viajya
Kilo Explorer

Hi @asifnoor

 

it helped me for creating popup box/dialog box,but if the dialog box contains choice list fileds,how the data will be stored to the tables when we select any choice in drop down list,for me the data is not storing in the table,can you suggest me for that?

asifnoor
Kilo Patron

Hi Vijaya,

you will still get the values in the client script when you use this line (assuming category is yoru choice list)

var cat = gel('my_category').value;

And then you can parse and store as per the data type that you have.

devservicenow k
Tera Contributor

How to create any incident record using this pop up features?

 

DNRS
Mega Explorer

I am working on UI pages where I need store values from popup box and based on the values stored from popup box I need to call a flow designer. But when I am trying to store those values through client script the are values are not holding in that field we I click ok the page gets reloaded and the values stored are cleared out. Someone help me with this.

Ranjith Ram
Tera Contributor
Hi @asifnoor / @josenava and Folks,

I have referred this community page.
My requirement is When I click on UI action button, it should pop-up a custom dialog box and it should show some fields getting from incident_task. After this by clicking a confirm UI action button, it should create a new record/task.
As given in this article, I have created an UI Page with onchange client script.
But kindly someone suggest, how this can be done with OnSubmit client script.

oprax02
Tera Contributor

This is very helpful and clearly explained, thank you. I want to call the UI page from an onLoad script of a new record and pass the values collected back the unsaved record?

Hemamani Prabha
Tera Contributor

Hi @asifnoor 

This is one such useful article. I just came across your article. Can you please help me with my query which is quite similar to this?

I have a requirement in which I need to see a preview or open the record of the selected roles field by clicking the field value.

HemamaniPrabha_0-1693227508170.png

This is the requested item form (service catalog). So this selected roles field is a multi line text field. Similar to how we have a preview icon for reference field I need to create one to show the preview of the selected fields. If I click one particular role can I open a UI page as a pop up that shows the preview of the particular field. Is this possible? Please help!!

 

erck
Tera Contributor

anyone know how to update the contents of the UI page depending on what the user selects from the UI page.

 

Like if the user selects a user and know we need to display the data for that user under the field. 

Version history
Last update:
‎09-22-2020 06:54 AM
Updated by: