How to call UI action on a form section using UI macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 03:19 PM - edited ‎05-25-2023 03:20 PM
Hi,
We have a UI action that is displayed a link under related links on the form. But user wants that link to be displayed on a section with the form. So, want to call this UI action using UI macro and formatter onto the form section. Please assist on how to call UI action through UI macro.
Here's the UI action code (when user clicks on the link, it returns name/value pair type):
This triggers on click of manageLocation()
function manageLocation(){
var label = getMessage("Manage Location");
var sys_id = g_form.getUniqueValue();
var loc = g_form.getValue('u_location');
if(loc) {
loc = JSON.parse(g_form.getValue('u_location'));
}
var arr = [ ];
Objects.keys(loc).forEach(function(key) {
arr.push(key + ': : :' + loc[key]);
});
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dd = new dialogClass('sn_apm_location');
dd.setPreference('sysparm_sys_id_ba', sys_id + ' ');
dd.setPreference('sysparm_loc', arr.toString());
dd.setTitle(title);
dd.setWidth(500);
dd.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2023 09:33 PM
• To call a UI action on a form section using a UI macro, you need to create a UI macro with a script that calls the UI action.
• The script should include the form section name and the name of the UI action you want to call.
• The script should also include the code to set the context of the UI action to the form section.
• The UI macro should be added to the form section.
• Finally, you need to add the UI macro to the form section’s UI policy.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2023 04:54 AM
Hi @sourav1999 , Appreciate the response. How to call the UI action using UI macro, can you please assist with the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2023 05:31 AM
Hi @sath
You can call UI action through UI Macro by bringing it in the form as UI formatter.
Please check this link you will get to know whole process how you can do it.
https://www.servicenow.com/community/developer-forum/ui-macro-call-a-ui-action/m-p/1780334
If my answer helps you resolved your issue then please mark it as correct or helpful.
Regards
Namrata
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2023 07:08 AM
Hi @Namrata Ghorpad , I have already checked the above link and followed the same process. After I added the formatter onto the form through form layout, I don't see it on the form