Calculate Records from Related List to Add to Field on Incident Table

Zo2
Tera Contributor

Hi All,

I am trying to "Calculate records from a related List to add to field on the incident table".

I imagine it would be a client script as i would need for it to update onLoad and onChange.

Im not too sure how i would write the script but think I should use the GlideAggregate function.

Your help/guidance is much appreciated

1 ACCEPTED SOLUTION

Hi,

So u_related_incident field stores the incident details.

Is it a string field or reference field ?

1) if it is string field then use this query along with other

gr.addQuery('u_related_incident',current.number);

2) if it is reference field then use this query along with other

gr.addQuery('u_related_incident',current.sys_id);

then it would give the count of new call records for this current incident and store that count in the count field

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

View solution in original post

12 REPLIES 12

Hi,

So it should give same row count when it runs in display business rule

Can you share what type of business rule you have written?

It should be display business rule

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

 

Please business rule details below.

find_real_file.png

 

find_real_file.png

Hi,

you want to populate value on incident field; so you need to have the display business rule on incident table

since the client script is also on incident table

change the business rule table to incident and check once

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Thanks Ankur....im now seeing the row count but it shows the same count (16) on all incidents, even if there is no calls related to the incident. Do you think its the encoded query causing the issue.

 

Appreciate all your help so far.

 

Kind regards

Hi,

That's because you are just querying with the call_type and u_related_incident fields

Does the u_related_incident store the incident number?

The query doesn't take into account the current incident record

Do you want to show the count of calls from new_call table where the caller in incident is same as the caller in new_call table?

If yes then have this query

var gr = new GlideRecord('new_call');

gr.addEncodedQuery('call_type=incident^u_related_incident!=NULL');

gr.addQuery('caller',current.caller_id);

gr.query();

var rowCount = gr.getRowCount();

g_scratchpad.rowCount = rowCount;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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