how to show/hide ci relationship formatter ?

Sachin Jain1
Giga Contributor

In our CMDB certain CIs having more than thousand related CIs and hence when we load a CI form it takes a lot of time to open that form. I was trying to remove the CI relationship formatter from the form and displaying it as a Pop-up in the click of an UI action. But I'm not able to find ci_relations.xml under UI macro. It seems it's written in source code. Any suggestions to achieve this functionality ? How to invoke ci_relations.xml   as a pop-up from UI Action ? I tried calling it as a UI macro from a UI page   but it didn't work.

1 ACCEPTED SOLUTION

will_leingang
ServiceNow Employee
ServiceNow Employee

Hi Sachin, I think GT is providing 2 different solutions in his answer - giving you some choices.



I spent quite a bit of time researching this for you and there is actually no way to put the ci relationship element in a popup or to load it after the form context. The way that it's built requires global jelly variables from GlideContext that can't be recreated in another context. so... here are a couple of alternatives.



  1. Good Idea: Create a different view, and put the ci relationships in that view but switch back to the default view when you don't want to see them.
  2. Better Idea: Create a new formatter that acts as a wrapper for the CI Relations formatter. This wrapper would control whether or not to show the CI Relations based on a querystring parameter. Here's an example:
  3. Create a new ui macro called: Load CI Relationships
    With the following XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <tr>
    <td>
    <j2:if test="$[sysparm_show_relations == 'true']">
    <g:inline template="ci_relations.xml"/>
    </j2:if>

    <j2:if test="$[sysparm_show_relations != 'true']">
    <button id="load_ci_relations">${gs.getMessage('Load CI Relations')}</button>
    <script>
    $('load_ci_relations').on('click', function(event){
    Event.stop(event);
    var redirectLocation = window.location.href;
    var hashLocation = redirectLocation.indexOf('#');
    if (hashLocation > 0)
    redirectLocation = redirectLocation.substr(0, hashLocation);
    window.location.href = (redirectLocation + '$[AMP]sysparm_show_relations=true');
    });
    </script>
    </j2:if>
    </td>
    </tr>
    </j:jelly>
  4. Follow this guide to create a new formatter following this guide: Creating a Formatter - ServiceNow Wiki
    1. Name: Load CI Relationships
    2. Table: Configuration Item [cmdb_ci]
    3. UI Macro: Load CI Relationships
    4. Type: Formatter
  5. Add this formatter to your CI form by modifying your form layout like GT suggested:
    Screen Shot 2015-02-03 at 7.36.46 AM.png

Then you will see a form like this:


Screen Shot 2015-02-03 at 7.52.50 AM.png


And when you click on that button... shazam...


Screen Shot 2015-02-03 at 7.53.02 AM.png




Not a perfect solution, but you should be able to make it work reasonably well.


View solution in original post

6 REPLIES 6

giora_tamir
ServiceNow Employee
ServiceNow Employee

You can find it under System UI > Formatters.


To remove permanently, personalize > form layout and remove User CI Relations (later named CI Relations) from the slushbucket.


Not the popup solution, but to show/hide via a client script (very hacky)



var p = $$('#root_node_xml')[0].parentNode;


p.style.display = 'none';



To turn back on:


p.style.display = '';


Hello Giora,



this   will hide the relationship from the form but still load it, which will not solve the problem.


any other sokution ?


will_leingang
ServiceNow Employee
ServiceNow Employee

Hi Sachin, I think GT is providing 2 different solutions in his answer - giving you some choices.



I spent quite a bit of time researching this for you and there is actually no way to put the ci relationship element in a popup or to load it after the form context. The way that it's built requires global jelly variables from GlideContext that can't be recreated in another context. so... here are a couple of alternatives.



  1. Good Idea: Create a different view, and put the ci relationships in that view but switch back to the default view when you don't want to see them.
  2. Better Idea: Create a new formatter that acts as a wrapper for the CI Relations formatter. This wrapper would control whether or not to show the CI Relations based on a querystring parameter. Here's an example:
  3. Create a new ui macro called: Load CI Relationships
    With the following XML:
    <?xml version="1.0" encoding="utf-8" ?>
    <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <tr>
    <td>
    <j2:if test="$[sysparm_show_relations == 'true']">
    <g:inline template="ci_relations.xml"/>
    </j2:if>

    <j2:if test="$[sysparm_show_relations != 'true']">
    <button id="load_ci_relations">${gs.getMessage('Load CI Relations')}</button>
    <script>
    $('load_ci_relations').on('click', function(event){
    Event.stop(event);
    var redirectLocation = window.location.href;
    var hashLocation = redirectLocation.indexOf('#');
    if (hashLocation > 0)
    redirectLocation = redirectLocation.substr(0, hashLocation);
    window.location.href = (redirectLocation + '$[AMP]sysparm_show_relations=true');
    });
    </script>
    </j2:if>
    </td>
    </tr>
    </j:jelly>
  4. Follow this guide to create a new formatter following this guide: Creating a Formatter - ServiceNow Wiki
    1. Name: Load CI Relationships
    2. Table: Configuration Item [cmdb_ci]
    3. UI Macro: Load CI Relationships
    4. Type: Formatter
  5. Add this formatter to your CI form by modifying your form layout like GT suggested:
    Screen Shot 2015-02-03 at 7.36.46 AM.png

Then you will see a form like this:


Screen Shot 2015-02-03 at 7.52.50 AM.png


And when you click on that button... shazam...


Screen Shot 2015-02-03 at 7.53.02 AM.png




Not a perfect solution, but you should be able to make it work reasonably well.


Thanks a lot Will Leingang. you provided me a perfact solution. you saved me