Form Variable Data to a Variable within a HTML Variable

danielbartholom
Mega Expert

Hi,

Looking for some assistance please. I am hoping I can explain what I am looking for as best as I can 🙂

I have a cat item with a number of variables on it:

First Name (first_name)
Last Name (last_name)
Email Address (email_address)

Finally I have a HTML variable called Preview (preview).

I am able to create an onChange Catalog Script that will do the following:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

function populateHTML() {
var fullName = g_form.getValue('full_name');
g_form.setValue('preview', fullName);

}
populateHTML();

}

Now this works ok however, this is what I am really looking for can I put something into the HTML variable that the form field (First Name) can reference to place the information to?

So person types First Name on the form > which will then look at the HTML variable and reference a variable inside the HTML variable (such as fname) and populate the information accordingly.

This sounds a lot simpler to explain in my head than on paper so I really do hope someone can help me.

Thanks

Dan

1 ACCEPTED SOLUTION

Wayne Richmond
Tera Guru

Hi Dan. I updated your other post with something that should work: https://community.servicenow.com/community?id=community_question&sys_id=4d991a88dbc64d90ae8125091396...

It's basic but does the trick.

View solution in original post

9 REPLIES 9

Janos,

To provide a little more information here for what I am looking to do:

find_real_file.png

That is possible, of course. Just have to concatenate (or interpose) text with (into) HTML code; e.g:

g_form.setValue('html', '<p>' + g_form.getValue('name') + '</p><p style="text-align: right;">' + g_form.getValue('surname') + '</p>');

Of course making sure that the values interposed or added are properly HTML escaped.

-O-
Kilo Patron
Kilo Patron

The code above in practice:

find_real_file.png

Wayne Richmond
Tera Guru

Hi Dan. I updated your other post with something that should work: https://community.servicenow.com/community?id=community_question&sys_id=4d991a88dbc64d90ae8125091396...

It's basic but does the trick.

Thank you Wayne, taking a look now.