- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 03:02 PM
Hi, I'm creating a form in a UI Page and want to pre-populate some fields from sys_user. The issue I run into is this error message: "The value of attribute "value" associated with an element type "input" must not contain the '<' character."
I've used the following script to pull the first_name field from sys_user:
<script>
<g:evaluate var="jvar_user_name">
var gr = new GlideRecord('sys_user');
gr.get('sys_id', gs.getUserID());
gr.first_name.getHTMLValue();
</g:evaluate>
</script>
Here's my HTML:
<table>
<tr>
<td><input type="text" id="first_name" name ="firstname" value="<g:no_escape>${jvar_user_name}</g:no_escape>"></input></td>
</tr>
</table>
Is there an alternate syntax to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 04:20 PM
Why are you attempting to add "<g:no_escape>" within the value?
Remove that tag, as there should be no need for that for anything you put into a text field.
If you absolutely need to add XML/HTML, consider using the innerHTML instead of value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 04:20 PM
Why are you attempting to add "<g:no_escape>" within the value?
Remove that tag, as there should be no need for that for anything you put into a text field.
If you absolutely need to add XML/HTML, consider using the innerHTML instead of value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 05:30 PM
Hey Stephen, I've used "<g:no_escape>" in my CMS and without it, the values won't show up. For instance, I've coded this in a Dynamic block:
<h1>Welcome to the team, <g:no_escape>${jvar_user_name}</g:no_escape> <g:no_escape>${jvar_user_lastname}</g:no_escape>!</h1>
Without "<g:no_escape>", the user's First and Last name do not show up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 06:52 PM
Ahh, well in your previous scenario(akin to innerHTML) you also could have also solved it by wrapping the entire value,
<h1><g:no_escape>${"Welcome to the team, "+ jvar_user_name+ ".. "}</g:no_escape></h1> (not saying one is better than the other, just illustrating the behavior)
It's going to be a lot more tolerant of reserved characters in innerHTML than it will in named attribute values.
In the case of value="..", it's going to resolve your phase 1 value before the browser evaluates the HTML. So while it doesn't like your tag within the value, you're ok because it's also unnecessary.
The browser won't see:
<input type="text" id="first_name" name ="firstname" value="${jvar_user_name}"></input>
it will see:
<input type="text" id="first_name" name ="firstname" value="Frank"></input>
The jelly editor syntax checker isn't perfect, it will incorrectly define some things as errors. Especially when setting element attributes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2016 06:39 PM
Hi Stephen, ok I got it to work. I moved the following code outside of <script>, then I deleted <g:evaluate> from the HTML and it now works. Thanks!
<g:evaluate var="jvar_user_name">
var gr = new GlideRecord('sys_user');
gr.get('sys_id', gs.getUserID());
gr.first_name.getHTMLValue();
</g:evaluate>