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

Chuck Tomasi
Tera Patron

Hi Nitish,



The processing script is run when you do a form submit. You can then get the input variables (e.g. text input named 'first_name' as variables in your processing script.



Example:


var gr = new GlideRecord('sys_user');


gr.first_name = first_name; // get value of first_name input variable.


// do other stuff


gr.insert()


Abhinay Erra
Giga Sage

Processing script can access the fields only when they are inside the <g:form> tags. See this link for more info


http://wiki.servicenow.com/index.php?title=UI_Pages#gsc.tab=0



danpatino
Tera Expert

Hi Nitish,



The processing script is intended to execute server side after the form is submitted.   If you want to run the processing script you need to make sure your button has type="submit" as an attribute.  



Unfortunately, this forces you to refresh (or navigate away from) the form.   If you can't handle a refresh but you still need some code to execute server side, I'm afraid the processing script is not the right place to put it.   You should instead use a combination of GlideAjax in the client script and a script include server side.



I hope this helps.


-Dan


ngo
Kilo Contributor

Hi Dan



Thanks for your reply and thanks for your idea of using glideajax


I tried making my button type="submit" but was unable to make the processing script work , tried enclosing it in function and also without it but nothing seems to work


also the input variable in html will be directly available in it since gel works only in client side


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


var description = des ; will take the value from the text box and feed it to the variable


Please comment if I am wrong anywhere



Thanks


Nitish Goel