Save a calculated field as a database record | Community
Skip to main content
CampaignerForLife
Level 5
Sep 22, 2023 8:47 AM UTC
Solved

Save a calculated field as a database record

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.
CampaignerForLife
CampaignerForLifeAccepted solution
Level 5
Sep 26, 2023 7:20 AM UTC

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

6 replies

CampaignerForLife
CampaignerForLifeAuthorAccepted solution
Level 5
Sep 26, 2023 7:20 AM UTC

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

Translate
LakshmiPravallika
New Participant
Sep 25, 2023 9:53 AM UTC

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.

Translate
AkshayAnand
New Participant
Sep 22, 2023 10:40 AM UTC

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

Translate
jorgeferreira
Level 3
Sep 22, 2023 8:56 AM UTC

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

 

 

Translate
CampaignerForLife
Level 5
Sep 22, 2023 9:15 AM UTC

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

Translate
jorgeferreira
Level 3
Sep 22, 2023 9:51 AM UTC

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

Thanks

Translate