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

Hello Will Leingang, I created UI macro and formatter as you mentioned and it's wotking.


But on some CI class I have "User CI Relations" formatter instead of CI Relationship formatter, for which I've created a new formatter "Load user CI Relationships" with same attributes as "Load CI Relationships" except Table: User [sys_user],


When I searched same formatter under Relationship section of form layout, I'm not able to find it (may be because it's on user table). Now the question is how to replace "User CI relations" formattor with "Load user CI relations". For ex. on cmdb_ci_appl table u'll find "User CI relations" formattor but when you'l remove it from form section and save it, it'll disappear.


Hi Sachin.


When I go to this list:



/sys_ui_element_list.do?sysparm_query=sys_ui_section.nameLIKEcmdb_ci%5EelementLIKERelations



I see 110 distinct elements that would have to be swapped out. You can probably do this quickly by editing them in the list... but to answer your question yes you will have to replace all of them. I'm not sure why saving it from the slushbucket isn't working like you'd expect.



Does this help?


Will