How to add UI macro on choice field

anshul_goyal
Kilo Sage

Hi Everyone,

Can anybody tell me how to add a UI macro to the choice field?

Thanks
Anshul

5 REPLIES 5

SyamPrasanM
Tera Expert

Hi @anshul_goyal 
You cannot directly place a UI macro inside a choice field itself in ServiceNow, you can use a combination of client scripts, UI policies, and custom UI macros to dynamically show content based on the user's selection in the choice field

To add a UI macro to a choice field in ServiceNow, you can create a UI macro and then write a script in the XML section:
  1. Go to System UI
  2. Select UI Macros
  3. Click New
  4. Give the UI macro a unique name and description
  5. In the XML section, write the script you nee
  1. Create a New Macro:

    • Click the New button to create a new UI macro.
    • Give it a Name (e.g., my_choice_macro) and fill in a Description.
    • In the XML field, define your UI macro using HTML and Jelly syntax. For example:
      xml
      <j:jelly xmlns:j="http://java.sun.com/jsp/jstl/core">
      <select name="${name}" id="${name}" class="form-control">
      <c:forEach items="${choices}" var="choice">
      <option value="${choice.value}">${choice.label}</option>
      </c:forEach>
      </select>
      </j:jelly>
       
    • Click Submit to save the macro.
      Add the UI Macro to the Choice Field
    • Navigate to the Table:

      • Go to System Definition > Tables and find the table that contains your choice field.
    • Open the Choice Field:

      • Locate the choice field in the list and click to open it.
    • Modify the Field Attributes:

      • In the Attributes field, add the following attribute:
        ui_macro=my_choice_macro
      • Replace my_choice_macro with the actual name of your macro.

Regards

Mule Syam Prasanna

PRAVAL-LOGO.png