Passing values from <script> to <j:set> in UI Macro

uma17
Tera Guru

Hi ,

can anyone let me know, how to pass value from script to Jelly in UI Macro

<script>     var name="XYZ"; </script>

<j:set var="jvar_user" value="${name}"/>  

<p>My Name is : ${jvar_user}</p>

I am not able to get the name value in <j:set>

6 REPLIES 6

Uma,



You have to create an Ajax transaction to go back to the server.



Jelly is Server side, the <script> tag is client side. You cannot have the server read information from the client synchronously. It must be fed back up to the server, processed and then responded to, so that the client can then react. This is done via Ajax requests, and in ServiceNow, the GlideAjax API.



Jake is correct in what he's saying, have a look at the following page and you can get an example running really quickly:



http://wiki.servicenow.com/index.php?title=GlideAjax



Thanks,


Alex


Hi Uma,



No I don't believe this is possible, because the <g:evaluate> tag is only processed before the form is loaded, which means the value you want to access would not exist yet (assuming this is a new catalog item being opened). If the catalog item had been previously saved into the cart, and the values were therefore saved on the form, it would be possible, however your script would have to access the variable value via a GlideRecord query, accessing the table that stores these values, rather than accessing the   value on the form's HTML (e.g g_form.getValue('var_name') etc).



Either way, because the <g:evaluate> tag is only processed before the form is loaded, you wouldn't be able to dynamically pass a variable value to it when the variable changes on the form (e.g like the way onChange scripts work). If you need to pass a variable value to a script that can only be run on the server, you could do this by calling a GlideAjax script from your onChange client script, and have it return a value to your client script for processing.



Regards,


Jake