add script generated HTML code to Ui Page

BerndKlus
Kilo Expert

Hi all,

is it possible to generate HTML code via Client script and use it as HTML?

e.g.

-------------------------------------------------------------------------

HTML:

<?xml version="1.0" encoding="utf-8" ?>  

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  

!!Generated code here!!

</j:jelly>

-------------------------------------------------------------------------

Clientscript:

var str;

if (x==y){

        str='some HTML code';

}

else{

        str='a different HTML code';

}

-------------------------------------------------------------------------

The result should be

-------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8" ?>  

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

!!Generated code here!!

some HTML code

</j:jelly>

-------------------------------------------------------------------------

Thank you in advance

Cheers Bernd

5 REPLIES 5

hmartind
Kilo Expert

In my opinion that would be kind of hacky and not a good practice.. May I ask what do you want to achieve? Maybe there is a better approach.



In the client Script you can use jQuery or JS to modify the DOM (add some html code for example) without the need to pass it to the Jelly Script.



Cheers!


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Bernd,



What is the exact requirement. Can you please elaborate.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

BerndKlus
Kilo Expert

The UI Page is (in my opinion) the best solution for my requirement.



Well, as asked in show/export a list as collapsible tree i want to display our Company struture of cost centers and stuff..



The whole hierarchy should be displayed in a tree view.. the elements have to be collapsible for a better overview!


I have figured out, that this can be implemented quite simple via html. CSS3 Treeview. No JavaScript


The source should be the cmdb_rel_ci table which I have already filled with all relationships..



I thought by myself, that I can create the list by a script and paste the result within the HTML code onLoad..



Cheers


cczernia
Mega Guru

Couldn't you build the html all in Jelly. Why build out the html in jelly and put it in a script when you can just have it output direct to the html? Is the condition something you can only pick up client side?



Jelly:


<g:evaluate var="jvar_mycondition" expression="getvalueofsomekind()" />



<j:if test="${jvar_mycondition == true}">


some HTML code


</j:if>



<j:if test="${jvar_mycondition == false}">


a different HTML code


</j:if>