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

Dan H
Tera Guru

Hi Dan,

Maybe you could provide some screenshots or redefine the requirement as it's a bit tricky to understand from my POV

Hey Dan,

Hopefully my most recent post will provide more information. Let me know if anything is unclear 😉

Thanks also for your reply

Cheers

Dan

-O-
Kilo Patron
Kilo Patron

Isn't re-generating the entire HTML an option? I mean the 1st name field changes -> re-generate the HTML including all other questions. Another question, say last name field changes, again re-generate the entire HTML with all question data included.

Hi Janos,

 

I hear what you are saying and makes absolute sense. However, what I would like to do is do some HTML formatting so basically right now if I do what you are suggesting the following would happen:
find_real_file.png

However, what I would like to do for example is have the first name on the left and the last name on the right....basically have the ability to move things around within the HTML. This is why I was wondering if you could map the form variable First Name (first_name) to something in the HTML variable like:

first_name (form variable) to fname (place holder in the HTML). 

This may not be something that can be done, but thought I would ask just in-case anyone has any experience with such a requirement?

Let me know if anything is not clear.