Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Macro GlideRecord Functionality

Ken83
Mega Guru

Hello All,

 

        I'm working on a UI Macro that should run a function when it is clicked. This function is supposed to go to the user record and modify a field. It's NOT working that way. The UI Macro is having values passed to it from Jelly scripting in a Dynamic Content block. I know the values being passed into it are accurate because if I do a gs.print and insert the Jelly variable names, it prints the correct data onto the screen. So in that Dynamic Content block, I invoked the UI Macro I wanted and passed the jelly parameters into it. I know the parameters are being passed correctly because one of them is a title value that I modified in the Dynamic Content block. When I do that, the UI Macro shows up with the new information. So my data that I am passing in is accurate. I created a function using <script> tags in the UI Macro. This is a standard GlideRecord function but it's not doing anything. I've tried using the JEXL expressions in the query and I've tried jelly.jvar_variable_name and neither one give the desired results. Does anyone know how to run a GlideRecord query from a UI Macro using Jelly Variables?

3 REPLIES 3

agulati
Kilo Expert

HI,


You could do something like the below code in your UI Macro



<g:evaluate jelly="true">


  var testgr = new GlideRecord("test_Table");


  testgr.addQuery("sys_id",jelly.sysparm_sys_id);


  testgr.query();


</g:evaluate>



Hope this helps.



-Aman


This didn't actually fix my problem but definitely pointed me in that direction. So that problem is resolved but it did lead to another problem. Now that I have the functionality I wanted, The 'Status' does not show the way I need it to. So here is the layout...



- Name -


- Status -


- Integer Value -


- Integer Value -


- Integer Value -


- UI Macro to change status -



When I go to Content Management module and click the page and then click 'Edit Page', the 'Status' value shows like I need it and it updates at refresh like I need it. The problem is then, if I click 'Preview Page', it opens in a separate window with the URL /cms/page_name. When it actually opens as a CMS page, the script does not appear to function. Any idea why the javascript does not function on a CMS page? Below is the script...



<j2:if test="$[!jvar_tlgarrett_status]">


<script>


document.getElementById("stat").innerHTML = "Not Available";


document.getElementById("stat").style.color = "red";


</script>


</j2:if>



I know the value of $[jvar_tlgarrett_status] equates to TRUE which should set the 'Status' field above to 'Not Available' in red lettering. Again, this works when I 'Edit Page' but not when I 'Preview Page'.


Sraj1
Giga Contributor

jelly.sysparm_sys_id --- what does this display? is it a sys id of a logged in user?