Calculated value on a scoped table

Anish Reghu
Kilo Sage
Kilo Sage

Dear coders,

 

Scoped table - x_abc

Field A - fieldA

Field B - fieldB

Field C - fieldC

All are strings.

How do I concatenate Field A and Field B using the calculated field on Field C.

 

Note - I am aware of the performance issues. But still, if this is the ask, what's the solution?

 

Also, how is the Function field different from Calculated field in this context?

 

Many thanks,

Anish

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi

there is no difference for handling calculated columns between scoped and non-scoped tables.

A good example is the name column of the sys_user table you can take as a blueprint:

 

https://[YOUR  INSTANCE].service-now.com/nav_to.do?uri=sys_dictionary.do?sys_id=84a50c3121120110a866589604c20d70%26sysparm_view=advanced

 

And in a function field only has some restricted and predefined functions can be used. For example the agent_utilization column of the awa_agent_capacity table has the following definition:

 

glidefunction:multiply(divide(workload,applied_max_capacity),'100')

Thanks Maik, makes it clear.

 

Regards,

Anish

Riya Verma
Kilo Sage
Kilo Sage

Hi @Anish Reghu ,

 

Hope you are doing great

 

In the "Calculated Value" section of field C, write the code to concatenate Field A and Field B using the appropriate scripting syntax. For example, in JavaScript, you can use the '+' operator to concatenate strings.

 

var concatenatedValue = current.fieldA + current.fieldB;
current.fieldC = concatenatedValue;

 

 

let's address the difference between Function field and Calculated field in this context:

  1. Calculated field: As we used above, a calculated field is a field that derives its value through a specified script or formula. It is updated automatically based on the script whenever the record is created or updated. Calculated fields are generally used to perform simple computations or concatenate values from other fields.

  2. Function field: A function field is a more advanced feature in ServiceNow. It allows you to define a reusable script that can be called from different parts of the system. Function fields are not limited to updating a single field, and they can perform more complex operations involving multiple fields and conditions. They are suitable for complex calculations or business logic that needs to be reused across different parts of the application.

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Thanks Riya for the quick response. I tried it the same way, you had mentioned earlier sa well.

 

But it didn't work. Now I made the change:

 

return concatenatedValue; // (works)

Earlier it was

 

current.fieldC =concatenatedValue // (which didn't work)

 

I think the reason is that calculated field doesn't store the value (onLoad). So, this logic justifies the behavior of the code.

 

NOTE - If you could please modify your code to the above said, I will mark your response as solution for others to view it as so.

 

Something more learnt. Thanks!

 

Regards,

Anish