Create a modal with text input

Solomon7
Tera Contributor

We currently have an onSubmit client script in Incident that triggers a prompt component pop-up under certain conditions. It would ask users to enter texts:

find_real_file.png

If "Proceed" is entered correctly, the record saves, and if not, it aborts.

Is there a way to make this a modal? I have looked around and only seen modals without the text field.

Thanks,

Solomon

 

 

 

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Hello ,

yes we can do it through sPModal Api

follow below steps :

1) In your on submit client script use this .

spModal.open is a method which is used to open modal windows and you can call your widget in widget parameter where you can create your input box.

You can change your title accordingly using title attribute 

and you i widget parameter use your widget iD 

Size you can have three sizes , xs,md,lg where i gave medium

function onSubmit()
{
	
		spModal.open({
			title: 'MY MOdal',
			widget: "my_modal_id", 
			widgetInput: "",
			size:"md"
		}).then(function(){
			
		}) ;   
	

}

find_real_file.png

2) Create a widget with the same ID that you mentioned in widget parameter

find_real_file.png 

Navigate to widgets -->create new -->paste below HTML script

<div>
  <label for="mytext">My Input:</label>
  <input type="text" id="mytext" name="mytext">
</div>

For more info on spModal Api refer below link :

https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/SPM-open_O

please mark my answer correct if it helps you

 

I tried what you suggested, and this is the error message I got. 

find_real_file.png

How do I resolve it?