Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog variable value from script

magnushedlu
Tera Guru

Hi,

 

I have a catalog form where one of the variables are a reference to the cmdb for the user to select a server.

Based on this server I would like to have a read only field that dynamically lists any Application Service that has either has a "Depends on" or "Hosted on" type of relationship to the selected server.

How can I achieve this?

 

I assume that I need to work with the cmdb_rel_ci table and I guess I need to write a script in some way. I really appreciate any input I can get.

7 REPLIES 7

Think I solved my own question.... I was looking at normal client script but I guess the catalog client script is the correct place 🙂

Hi,

 

I do not get your script to work.

I tried to simplify it to exclude issues but sill no luck.

 

When looking in the browser console, I get this issue. 
"synchronous use not supported in Mobile or Service Portal unless message is already cached"

 

This is the Script include that I use to test with based on your input.

 
 getRelatedServices: function() {
        var serverId = this.getParameter('server_to_decomission');
        if (!serverId) return '';

        var serviceList = [];
        var gr = new GlideRecord('cmdb_rel_ci');
        gr.addQuery('child', serverId); // "Depends on" relationship
        //gr.addQuery('type.name', 'IN', 'Depends on::, Hosted on::'); // Filter by relationship type
        //gr.addQuery('parent.sys_class_name', cmdb_ci_service_auto); // Filter for app service class
		gr.query();

        while (gr.next()) {
            var appService = gr.parent.getDisplayValue();
            if (appService && serviceList.indexOf(appService) === -1) {
                serviceList.push(appService);
            }
        }

        return serviceList.join(', ');
    };
I changed the first addQuery as servers are childs to App. Services

@magnushedlu 

if your reference variable is referring to cmdb_ci then update as this

 getRelatedServices: function() {
     var serverId = this.getParameter('server_to_decomission');
     if (!serverId) return '';

     var serviceList = [];
     var gr = new GlideRecord('cmdb_rel_ci');
     gr.addQuery('child', serverId); // "Depends on" relationship
     //gr.addQuery('type.name', 'IN', 'Depends on::, Hosted on::'); // Filter by relationship type
     //gr.addQuery('parent.sys_class_name', cmdb_ci_service_auto); // Filter for app service class
     gr.query();
     while (gr.next()) {
         var appService = gr.parent;
         serviceList.push(appService.toString());
     }

     return serviceList.toString();
 };

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader