How to add UI macro on choice field
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2024 10:07 AM
Hi Everyone,
Can anybody tell me how to add a UI macro to the choice field?
Thanks
Anshul
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2024 03:32 AM
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:
- Go to System UI
- Select UI Macros
- Click New
- Give the UI macro a unique name and description
- In the XML section, write the script you nee
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.
- In the Attributes field, add the following attribute:
Regards
Mule Syam Prasanna