How to call UI action on a form section using UI macro

sath
Tera Expert

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();
}

 

 

7 REPLIES 7

sourav1999
Mega Guru

• 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

Hi @sourav1999 , Appreciate the response. How to call the UI action using UI macro, can you please assist with the code?

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 

 

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