The Zurich release has arrived! Interested in new features and functionalities? Click here for more

UI Page HTML Tag Issue?

warren_chan
ServiceNow Employee
ServiceNow Employee

Hi all,

I'm trying to write a simple query in the HTML section of my UI Page:

<g:evaluate>

                      var today = new GlideDateTime();

                      var kb = new GlideRecord('kb_knowledge');

                      kb.addQuery('valid_to','>=',today);

                      kb.addQuery('published','<=',today); // Error here?

                      kb.query();

</g:evaluate>

However, the system won't let me save this due to the following error:

Error MessageError at line (26) The content of elements must consist of well-formed character data or markup.


I suppose that is because of the '<' character being interpreted as an HTML tag. I've tried using the escape character for HTML, but still no luck.


Any thoughts?

1 ACCEPTED SOLUTION

Community Alums
Not applicable

I've updated your code to escape your > and < for the UI Page. Also, I've added parameters to your g:evaluate tag to allow your query to be used by other parts of the document as 'jvar_kbarticles'. the last line of an evaluate becomes the value of the variable defined by it. (in this case, 'jvar_kbarticles' will contain the object 'kb' and can now be used by other elements of your document.)



<g:evaluate jelly="true" object="true" var="jvar_kbarticles">


      var today = new GlideDateTime();


      var kb = new GlideRecord('kb_knowledge');


      kb.addQuery('valid_to','&gt;=',today);


      kb.addQuery('published','&lt;=',today);


      kb.query();


      kb;


</g:evaluate>



Hope this helps!


Jerimy


View solution in original post

2 REPLIES 2

Community Alums
Not applicable

I've updated your code to escape your > and < for the UI Page. Also, I've added parameters to your g:evaluate tag to allow your query to be used by other parts of the document as 'jvar_kbarticles'. the last line of an evaluate becomes the value of the variable defined by it. (in this case, 'jvar_kbarticles' will contain the object 'kb' and can now be used by other elements of your document.)



<g:evaluate jelly="true" object="true" var="jvar_kbarticles">


      var today = new GlideDateTime();


      var kb = new GlideRecord('kb_knowledge');


      kb.addQuery('valid_to','&gt;=',today);


      kb.addQuery('published','&lt;=',today);


      kb.query();


      kb;


</g:evaluate>



Hope this helps!


Jerimy


Thanks Jerimy. I could've sworn I did the exact same thing, but I must have missed the other tags in the element header.