Calculated view show in list view

azabielski
Mega Expert

Is there a way i can show a calculated field value in a list view, i've tried through business rules and the calculated value it self and i am not able to see it once switched to the list view only when i view each individual record.

The use case is when we need to bill someone for an over usage of something i need that last value that needs to be billed a calculated value based on the overage amount and the overage price so that multiple records can be seen/selected at once of all the overage prices and execute a custom ui action on all those rows.

1 ACCEPTED SOLUTION

If I am understanding your requirements correctly, the only thing you can do is create a new table that joins the tables together with a pseudo calculated field as shown in my example.



New Table


Field 1: Reference table A


Field 2: Reference table B


Field 3: You field calculated via business logic



Create before update/insert business rule to populate value of field 3.


Dot walk as required to show fields on table A or B in the list.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

10 REPLIES 10

Database views can only be used for joining tables.


It doesn't handle calculations or logic of any kind.



'Calculated fields' are essentially virtual, so they cannot work in DB views.


You will need to use some sort of external reporting solution.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Right so back to my orginal question, what is the best way to do what i am trying to accomplish leveraging the full use of the product. I need a solution not regeritaed roadblocks and common KB answers please.


If I am understanding your requirements correctly, the only thing you can do is create a new table that joins the tables together with a pseudo calculated field as shown in my example.



New Table


Field 1: Reference table A


Field 2: Reference table B


Field 3: You field calculated via business logic



Create before update/insert business rule to populate value of field 3.


Dot walk as required to show fields on table A or B in the list.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Thank you very much for this , i think i understand the approach i'll try this out. So once i have the raw data i would have a UI action to write to this third table to give me a proper bill ? I am understanding that fully?


So i think this solution works but i am getting a duplicate key issue



Unique Key violation detected by database (Duplicate entry '9d42abfbdb50b6005524fbec0f96196e' for key 'PRIMARY')



Invalid insert


But it does insert properly just this error comes up for almost no reason..
here is my business rule.

(function executeRule(current, previous /*null when async*/) {



  var bwOver = current.u_raw_95th_data.u_total_used - current.u_master_95th_table.u_bandwidth_purchased;


  if(bwOver > 0) {


  current.u_bandwidth_overage = bwOver;


  current.u_overage_bill = current.u_master_95th_table.u_overage_bandwidth_price * bwOver;


  } else {


  current.u_bandwidth_overage = 0;


  }



  current.update();



})(current, previous);