Expand my Community achievements bar.

SOLVED

Save a calculated field as a database record

Avatar

Level 7

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?  

1 Accepted Solution

Avatar

Correct answer by
Level 7

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

View solution in original post

6 Replies

Avatar

Level 3

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

 

 

Avatar

Level 7

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

Avatar

Level 3

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

Thanks

Avatar

Community Advisor

Hi @CampaignerForLife 

 

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

 

AkshayAnand_0-1695379093714.png

 

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

 

AkshayAnand_1-1695379172492.png

 

Regards

Akshay

Avatar

Community Advisor

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.

 

LakshmiPravallika_0-1695635412476.png

 

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

 

Regards,

Pravallika.

Avatar

Correct answer by
Level 7

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