How do I use script to modify the HTML in an HTML field on a catalog item

mikereaves
Tera Expert

I want to add more HMTL to an HTML field that already has HTML in it.

As my user interacts with a catalog item, I want to add rows to an established table in an HTML control.

The HTML field appears on the catalog item and contains a table (with the heading row).

I want to edit the table using a UI Macro.   The user will put text into a single text box and clicks an "Add Row" button placed on the form by a UI Macro field.

When the user clicks the button the UI macro will add a new row to the table in the HTML field.

The problem I'm getting is that although the UI macro can get the text from the single text box and wrap html around it, the result always appears without the HTML.

Here's the UI Macro:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <j:set var="jvar_n" value="add_row_${ref}"/>

  <a id="${jvar_n}" onclick="addRow('${ref}')">

  <button>add row</button>

  </a>

 

    <script>

    var HTMlist, newHTMLlist, newTblRow;

   

          function addRow(reference) {

        getList();

        concatRow();

   

        newHTMLlist = HTMLlist + newTblRow;

        g_form.setValue('whole_thing', newList);

        g_form.setValue('list', newHTMLlist);

   

        clearRow();

          }

      function getList() {

        HTMLlist = g_form.getValue('list');

    }

      function concatRow() {

        newTblRow = "&lt;tr&gt;&lt;td&gt;" + g_form.getValue('name') + "&lt;/td&gt;&lt;td&gt;" + g_form.getValue('address') + "&lt;/td&gt;&lt;td&gt;" + g_form.getValue('phone') + "&lt;/td&gt;&lt;/tr&gt;";

      }

      function clearRow() {

        g_form.setValue('name','');

        g_form.setValue('address','');

        g_form.setValue('phone','');

    }

  </script>

</j:jelly>

Any suggestions would be greatly appreciated.

Thanks,

1 REPLY 1

Mujtaba Amin Bh
Mega Guru

Just a suggestion: Instead of doing so much coding why don't you use Catalog Table Variables:



ServiceNow Share



I think this will serve your purpose.