Save a calculated field as a database record | Community
Skip to main content
CampaignerForLife
Level 5
September 22, 2023
Solved

Save a calculated field as a database record

  • September 22, 2023
  • 4 replies
  • 1511 views

Hello, is there any way to save a calculated field by expr in database? 

 

When I create a calcualted attribute, it's only saved as XML and not as a database record. I want to keep them after being calculated, so I can make an index. Is there any way?  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by CampaignerForLife

I finally did it creating a Trigger with an SQL Code, all the other options wouldn't create an SQL column

4 replies

jorgeferreira
Level 3
September 22, 2023

Hello,

 

You can create a dedicated field in the schema and then you can either

  • Use a workflow to calculate the expression from time to time and store it
  • OR, upon writting a record, calculate the field and store it

 

 

CampaignerForLife
Level 5
September 22, 2023

How could I do the second option?upon writting a record, calculate the field and store it

jorgeferreira
Level 3
September 22, 2023

Could you provide more information on the schema you have the calculated field and which expression are you using?

Thanks

AkshayAnand
Community Advisor
Community Advisor
September 22, 2023

Hi @campaignerforlife 

 

You can use the below code as an example to create a calculated field and insert in the schema.

 

 

var UUID=getUUID(); logInfo("UUID = "+UUID); sqlExec("insert into CusSequenceTest( sEmail ) values ('"+UUID+"');");

 

 

Regards

Akshay

LakshmiPravallika
Community Advisor
Community Advisor
September 25, 2023

Hi @campaignerforlife ,

 

You can create the Index directly on the Calculated attribute as shown below

 

For Example, consider you have created the Calculated field on @email , then you can use the below syntax as an example for Calculating the length of this field.

 

<attribute desc="Test calc field" expr="Length(@email)" label="EMAIL_TST" name="tstEmail"
type="string"/>

 

and then create the Index in the Schema as shown below:

 

<dbindex name="PK_TstEmail12" unique="true">
<keyfield xpath="@tstEmail"/>
</dbindex>

 

It will allow you to create the index on this calculated field.

 

 

Also you can try Updating the Values into the Schema by using sqlExec command using the workflow.

 

Regards,

Pravallika.

CampaignerForLife
CampaignerForLifeAuthorAccepted solution
Level 5
September 26, 2023

I finally did it creating a Trigger with an SQL Code, all the other options wouldn't create an SQL column