- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 03:10 PM
Help, how do successfully put an attribute inside a HTML tag inside a string without jelly compiler complaining and preventing me from saving? This is what it should be syntactically when it's just javascript and not put inside jelly:
<script>
//Get some dynamic value via GlideRecord
//.... you get the idea...
//Write the dynamic HTML using this value
var dyn_html = "<table><tr><td colspan=\'2\'>" + dyn_value + "</td></tr></table>";
//Write the content
document.getElementById("dyn_content").innerHTML=dyn_html;
</script>
Error thrown when save is: Open quote is expected for attribute "colspan" associated with an element type "td".
The Service Now UI complains about saving it until I adjust it to this where the quotes are NOT escaped which makes the code not work. So, this allows me to save, but at that point, it doesn't work because the single quotes need to be escaped and I get a console error when running client side:
<script>
//Get some dynamic value via GlideRecord
//.... you get the idea...
//Write the dynamic HTML using this value
var dyn_html = "<table><tr><td colspan='2'>" + dyn_value + "</td></tr></table>";
//Update the content
document.getElementById("dyn_content").innerHTML=dyn_html;
</script>
I'm sure there's some weird way to escape this for jelly or tell it to stop validating an attribute within a string that should not be validated because it's technically a string and not code, but I don't have a clue.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:28 PM
Below code works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 09:28 PM
Below code works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 06:59 AM
Indeed it does. Thanks @Gurpreet07 . The only slight change, but we all get the idea (was missing one single quote after the "2">.
<script>
//Get some dynamic value via GlideRecord
//.... you get the idea...
//Write the dynamic HTML using this value
var dyn_html = '<table><tr><td colspan="2">'+ dyn_value + '</td></tr></table>';
//Write the content
document.getElementById("dyn_content").innerHTML=dyn_html;
</script>