UI macros

UI macros are scripts that can be included in UI pages and in other areas throughout the ServiceNow platform. By separating them out from individual UI pages, it makes them easy to reuse across the platform, too.

UI macros are seen throughout the ServiceNow platform, running the service catalog cart and approval summarizers. Let's have a look at how they are created.

A UI macro is quite a simple form, with only a few fields. First, we need to give our UI macro a name. After that, we can add a description, and then complete the XML field. The XML field is an XML type field and works in a very similar way to the HTML field on a UI page. We fill in the XML field with the Jelly script we want to run when this UI macro is run.

We are also given the same Jelly code that we are given when creating a new UI page in the XML field:

<?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:jelly>

To recap, these tags introduce Jelly scripting, and we can start writing our Jelly script inside the Jelly tags.

We can also invoke a macro from a UI page by using a macro_invoke tag. Let's see how this works:

<g:macro_invoke macro="kb_article_footer" />

We use the macro_invoke tag and the macro parameter to invoke our UI macro. We just need to give the name of the UI macro in the macro parameter, as in the preceding example. This example will invoke the kb_article_footer UI macro.

It is possible to invoke a UI macro inside a UI macro, too. To do this, we use a g tag with the name of the macro inside the tag. We can see how this works in the script:

<g:ui_button />

This will invoke the ui_button inside this UI macro.

UI macros are a great way of writing chunks of Jelly code that can easily be reused throughout the ServiceNow platform. They are especially useful to add to your UI pages. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.67.166