How to write query to find count for a condition

Anna_Servicenow
Tera Guru

I have the below scenario:

 

User is entering server name in the catalog form field(reference :windows server table).

1.If it is one server name it should accept(count is 1 now)

2. if two server are selected, then for second it should check if parent has "citrix" in name, If yes count is 1 now. If no :citrix in name of parent, count becomes 2. field value in form clears off as error.

 3. if two server are selected, then for second it should check if parent has "citrix" in name. User enters 3rd server name- count is now 2  field value in form clears off as error.

 

I have the below SI for case 1. It is not working for case 2 and 3. Please help 

 

var count = 0;
        var server = this.getParameter('sysparm_server');
        var serverrel = new GlideRecord('cmdb_rel_ci');
        serverrel.addEncodedQuery('parent.operational_status=1^parent.sys_class_name=cmdb_ci_service_discovered^child.sys_id=' + server);
        serverrel.query();
        while (serverrel.next()) {
            count++;
        }
        gs.log("count"+count);
        return JSON.stringify(count);

 

5 REPLIES 5

Community Alums
Not applicable

Hi @Anna_Servicenow ,

 

Sorry, but I'm not able to understand your requirement. 

I want to understand the behavior of catalog item form, fields, tables, and mainly your requirement. Please provide all the details which are required for your scenario.
For e.g. screenshot of the catalog item form, all the necessary backend tables names, fields, and their types, ++ things that you think might be important.

 

So, that I can try this on my PDI and respond with a working solution 🙂

 

regards,

Prasad