show record values in HTML field in backend, NOT SP NOT widgets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2024 06:22 AM
Hello Experts, I wish you all well.
I am using HTML fields in my form to allow users to add their content to the backend form similar to the "Build Terms and Conditions" UI Action and how it allows users to create records containing language blocks (terms and conditions for a contract) into the form itself in the backend. In the PDI the UI Action is named: "build_terms" on the table: "ast_contract".
They want to incorporate field values directly into their HTML content, but I do not know how to enable this directly within the HTML field, similar to a UI Macro.
I am doing this for them in the UI Macro language by using "$[current.field_name]" to display the field's value, but they want to replicate this same behavior in their HTML field content blocks so that a record's field value is inserted into the text when the setValue happens. I will continue my research and add a solution when I find it, but hoping one of you experts can show us the right way to do this. My initial psuedo-code is as follows:
The table I am using for the Service Descriptions (HTML-formatted user input):
0. USER IS ENTERING INFORMATION INTO A HTML FIELD AND WANTS TO REFER TO A FIELD VALUE IN THE AGREEMENT RECORD
1. var hotAgreement = new GlideRecord(agreement_table);
2. hotAgreement.get(g_form.getValue(agreement_reference_field_in_service_record);
3. USE HOTAGREEMENT FOR VALUES COLLECTION AND ASSIGNMENT IN HTML FIELD
4.
The table containing the contract/agreements (target for service descriptions)
1. USERS CLICK THE BUILD AGREEMENT TERMS CUSTOM UI ACTION, THIS PART WORKS
2. HTML CONTENT CONTAINS VALUES FROM THE AGREEMENT RECORD FIELDS, WANT TO DO THIS
Kind Regards,
Woody
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2025 05:05 AM
Are you trying to pull field values from a different record than the one where you're executing the UI Action into the UI Action or field values from the same record?
If from the same record, you can use g_form.getValue('field_name') or g_form.getDisplayValue('field_name') to get the values from the record within a UI Action.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2025 06:03 AM - edited ‎01-12-2025 06:04 AM
I am not aware of a built-in process to insert values into variable placeholders within the HTML field, but you can do this with a client script. Once you have set the field or condition that determines what the variable values should be, then trigger the client script to do simple text replacement within the html field. If I understand your situation correctly, then the trigger would be when the agreement field is changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2025 04:57 AM
Thank you for your insights John. I think it might be possible to use a business rule to capture the record's field names and values in a series of scratchpad variables, which I can then (somehow) incorporate into the header of the html field's code, perhaps using an onLoad client script to insert a block of html code into the field when the form opens the first time. It can be a static block of code referencing a static collection of values, and since the hidden html code can be edited using the ("<>") button in TinyMCE on the form, users can correct erroneous values, all without having to submit a request and wait for me to edit the form's UI Macro content then wait for the next release.
This is my goal: to replicate the behavior of the UI Macro's ("$[current.address]") within the html fields on the form, so users can reference the record's data in a nicely formatted block of text.
Ultimately, I will use the html fields to construct a dynamic pdf form that I will use to capture e-signatures, making the contract enforceable.
Thanks again for the dialog and ideas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2025 04:20 PM - edited ‎01-14-2025 04:21 PM
A quick note: I found this community post with some valuable guidance from @Aman Kumar S basically demonstrating that the client javascript will work to retrieve field values and insert the into the html field, using the Default Value field in the dictionary entry form. What I will experiment with over the next few days is using this approach to collect some of the key field values, assign them to hidden inputs, then test to see if I can use the hidden input variables in the body of the html field. This is the closest I've come to finding guidance on this code challenge, thank you Aman. Updates to follow in a day or so.
How to get values of fields and put it on an HTML ... - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2025 04:43 PM
I did post that in this thread earlier today that you could use g_form: https://www.servicenow.com/community/developer-forum/show-record-values-in-html-field-in-backend-not...