Calculated field not working in report

Ahmmed Ali
Mega Sage

Hello All,

I have created one calculated field on server table (cmdb_ci_server), in which i have script as "return current.cpu_count*curent.cpu_core_count". the field type is integer. this is working fine in form view and list view of server table. even it is working fine if we take report on server table.

but if i take report on configuration item and add above field to the report, it is not showing the values.

to debug, i have created same field with same calculated script in windows server table (cmdb_ci_win_server) and i added this field in cmdb_ci table report, it is working.

for server table field the value is not showing in list view.

Note: both cpu count and cpu core count fields are on computer table.

below is screenshots for reference.

here windows server table field is showing data but server table field is not showing the data.

at the same time, if i take report on server table, i am getting data in both the fields (i.e windows server table field and server table field).

Please help me to resolve the issue.

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali
6 REPLIES 6

Adam Stout
ServiceNow Employee
ServiceNow Employee

I'm not sure why it wouldn't be working, but have you looked at converting this to a Function field?  It should be more efficient for simple calculations like this:

https://docs.servicenow.com/bundle/kingston-application-development/page/build/platform-functions/ta...

If you aren't on Kingston yet, I would materialize the field and populate it with a BR when either of the fields changes.  If you do it in a calculated field, you are calculating this every time you view it, but since only changes when one of the dependent fields changes, you are calculating and recalculating it needlessly.

Hi Adam,

 

Thank you for response.

I got to know about function field from this. this would have helped me, but issue is i that this field is will not be available i cmdb_ci (parent) table report. I checked it and am not getting in cmdb_ci report and i am getting this field only if i run the report on server table as i have this field on server table.

 

also i found the issue why i am not getting the values in calculated field. if i update anything on any server record, for that record calculated field data is showing in cmdb_ci report only for that record. for server table report is is showing the data without any update. but for parent table report, it it is showing data only if we update that record.

 

is it expected behavior?

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

I'm not sure if I am following exactly and I'm not familiar with the extensions of these tables to know what we should expect. 

I could see some issues if you have the calculated field a table that requires data from an extension lower on.  There may be a JavaScript syntax that handles this but without digging into the instance, I can't tell you what that is exactly.  Can you move the calculated field to the same table where the all the data is?

Actually the data fields are on computer table and the calculated field is on server table (child of computer table). our requirement is to have the calculated field on server table itself. so cannot move the field to computer table.

 

but my question is if we update anything on the server record or create new record in server table then for that field the calculated field is showing the vale in cmdb_ci report.

but for older records it is not showing the data in the field.

 

i think the calculated field is not saving the record when the record is queried in parent table report. Ideally all the calculated fields should update whenever the record is queried and also the record should update with new calculated value, but unfortunately it is not happening.

I think this is not with my instance issue only, as i was able to replicate the same in our office development and testing instances. 

Thanks,

Ali  

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali