How to trigger a processing script in UI page through button

ngo
Kilo Contributor

Hi Folks ,

I am creating a form in UI page and the fields on the form needs to be updated in Service now after click of a button on the page

I was able to do it via client script but it is taking some time and it is not the best practice

All I want is to trigger the processing script on the click of the button and then i will write my code inside it and not in client script

Thanks & Regards

1 ACCEPTED SOLUTION

+ 1 to Chuck's response.   Also, I didn't see any form tags in your snippet.   Make sure you include the jelly version of those.  



Here is a quick example of what should work.  



find_real_file.png



find_real_file.png


View solution in original post

8 REPLIES 8

The variable name goes off the name attribute of your input. It should be name="des", not id. The "id" attribute is used more for CSS or getElementById() methods. I suspect you don't need either here. You can have it there and still call it des, but it won't do you anything in the processing script. That all comes from name="des".



<div>Short Description: <input type="text" style="height:30px;" name="des" size="50" /></div>


+ 1 to Chuck's response.   Also, I didn't see any form tags in your snippet.   Make sure you include the jelly version of those.  



Here is a quick example of what should work.  



find_real_file.png



find_real_file.png


ngo
Kilo Contributor

Hi Dan/chuck



Thanks for your swift response , It worked like a charm



Regards


Rob Humphries
Tera Expert

I had this problem and came up with a slightly different solution so posting incase anyone else finds this thread.

 

I agree that in almost all cases you should use <g:ui_form> tags around your form inputs and then the when you have a <button type="submit"> it will trigger the processing script automatically and you will be able to access the inputs by id like request.getParameter("field_id")

 

My problem was slightly different because I wanted to render all my HTML in server scripts and then use <g:no-escape> elements to display it. This makes working with Jelly on a large scale much easier especially after support for ES6 is available in script includes etc.

 

Anyway, with that you cannot use <g:ui_form> because it gets rendered inside the <g:no-escape> and errors.

 

So I had to use just a standard HTML <form> tag, but you can make this trigger the processing script.

 

<form method="POST" action="instance_url/ui_page_process.do?sys_id=YOUR_UI_PAGE_SYS_ID">

 

When a <button type="submit"> is pressed on that form the processing script will be run with all the form inputs available using resource.getParameter("input_id")