Want the script to count the number of records in the related list and reflect that number on the form.

swaroop
Kilo Sage

Want the script to count the number of records in the related list and reflect that number on the form.

I have a customized table and i created a related list of Incident in that customized table. I want count of the total records in the related list on the customized table form.

Can anyone help me with the code.

 

Thanks in advance.

2 REPLIES 2

agupta09
Kilo Contributor

var count=0;

var num= new GlideRecord('//Table name');

num.addQuery('parent',sysid);

num.query();

while(num.next()){

count++;

gs.info(num.number);

}

gs.info(count);

Gaurav Bajaj
Kilo Sage

HI,

If its a related list, you can query the related list table and get the number of records having the same incident number and then populate it on the main table.

You need to write display BR to get it done.

 

var gr = new GlideRecord('related list table');

gr.addQuery('column_name', current.sys_id); //column should be reference field here

gr.query();

var count = gr.getRowCount();

g_scratchpad.ticketCount = count;

 

Now you have the ticket count in scratchpad variable. Please write an onload client script to fetch the ticketCount in the form and after that its up to you if you want to populate it under some field or just add an informessage at top of the form.

 

g_form.addInformessage(g_scratchpad.ticketCount);

 

Please mark it correct/helpful based on the impact of the response.

 

Thanks

Gaurav