Custom Relationship (Defined Related List)

Kalaiarasan Pus
Giga Sage

I am trying to created a custom related list (Relationship menu) and able to setup the fields, script etc.

I am trying to not show the related list if it has no records. So I have set the 'Omit if empty' to true on list control.

Below is the format of my related list query script currently.

if(validData)

{

addquery to show the required data

}

If I am leaving the else part blank, it is end up pulling all the records from the table.

How would I handle the else part to return no data other than adding a invalid query? Is there a elegant way to do this?

11 REPLIES 11

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

There might be a misunderstanding on the functionality. The addQuery part only adds a filter on the current query from the table where it's applied. It means if you do not add a filter it will just get the entire table back.


Now, as a workaround (I haven't tested it), I would suggest you try in the 'else' clause something like this:



if(validData)


{


addquery to show the required data


}


else


{


current.setLimit(0);


}



Not the most elegant way indeed!


This picks out and displays 50 records which means there could be default value of setLimit function.



I am currently doing this as the else part to fail the query.


current.addQuery("sys_id",'x');


That's a bit strange, as I don't see a default limit set in GlideRecord class.



And running this on my own instance (jakarta):



var gr = new GlideRecord('incident');


gr.setLimit(0);


gr.query();



gs.print(gr.getRowCount());



I get:



[0:00:00.001] Script completed in scope global: script



*** Script: 0

This does appear to be running in background script but not on related list definition.