Custom Table - Dictionary Table - Calculated Value

Andres25
Giga Contributor

Hello,

I have a custom table with one field (u_result) that I want to be calculated based on boolean value of two other columns of the same table.

Something like:

If u_boolean1 == true and u_boolean2 == true 

u_result == true

I have seen that the calculated value feature of the dictionary entry has the script option but I'm not familiar at all with syntaxis. 

What would be the code for creating a function that validates both boolean values and if both are true set the result field to true otherwise set to false?

Thanks,
Andres.

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

HI Andres,

Calculated value has huge impact on performance. Calculated fields are calculated every time a row is read. This means any calculation that does complex processing is re-run on every row read. In an example with 100 rows, that means a calculated field, even one which isn't displayed on your list, is calculated once per row or 100 times per list. Often you can get the same results, and better performance by using an Insert/Update business rule to set a field value, rather than relying on a calculated field.

 

if you want to calculate the value on form Load or on value change you can go with Client scripts. If you want to calculate value on insert or update then you should choose to go with business rule. 

 

Client script structure

if(field_1 == true && field_2 == true)
   g_form.setValue('u_result', true);

 

 

Business rule structure

var field1 = current.field_1;
var field2 = current.field_2;

if(field1 == true && field2 == true)
  current.u_result = true;

 

Let me know which route you wanted to go, I will help you further on that if required.

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

 

Regards,
Muhammad

View solution in original post

6 REPLIES 6

Hi Muhummad,

CAn you please help me with my requirement.

I created a custom field u_aging_days , field type "string" which returns the range of days the incident created.

i have used the below script in calculated script but grouping is not working on incident table with calculated script. Can you help me in writing a business rule for the below script please.

 

(function calculatedFieldValue(current) {

// Add your code here
var gdtNow = new GlideDateTime();
var gdtActual = new GlideDateTime(current.sys_created_on);
var compare = gdtNow.compareTo(gdtActual);
var days, difference;

 

if (compare === -1) {

difference = GlideDateTime.subtract(gdtNow, gdtActual);
days = difference.getDayPart();

} else if (compare === 1) {

difference = GlideDateTime.subtract(gdtActual , gdtNow );
days = difference.getDayPart();

} else {
days = 0;
}


if(days>= 0 && days<1)
return "0 - 24 hours";
if(days>=1 && days<3)
return "1 - 3 days";
if(days>=3 && days<6)
return "4 - 5 days";
if(days>=6 && days<10)
return "6 - 10 days";
if(days>=10 && days<15)
return "11 - 15 days";
if(days>=15 && days<30)
return "16 - 30 days";
if(days>=30 && days<60)
return "30 - 60 days";
if(days>=60 && days<90)
return "60 - 90 days";
if(days>=90)
return "+90 days";// return the calculated value

})(current);

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi Andres,

 

Please mark my answer as correct if your issue is resolved.

 

Regards,

Sachin