Calculated Field in the Domain to check Difference of two dates

Hello Community,
I want to calculate the difference between two dates through domain ( Entity ) Formula=« true » field but still not able to generate it.

I have calculated difference in the form view through CDATA ,
Here is the code.

    <field name="$ageruntime" title="Total Experience" readonly="true" showIf="startDate != null &amp;&amp; endDate!=null">
      <viewer><![CDATA[
				{{
				 $moment(record.endDate).diff(record.startDate, 'years') + "  Years  " + 
				($moment(record.endDate).diff(record.startDate, 'months')%12 )+ "  months  "
				}}
      ]]></viewer>
    </field>

and the result is here:

From To Experience

1 « J'aime »

Hello,

First and foremost, regarding the domain attribute formula , it appears there was a misunderstanding. The attribute formula is actually a boolean attribute that specifies whether the field’s value should be treated as an SQL formula or not. You can find more information about it in the documentation here: link to documentation.

However, the requirement you mentioned can still be achieved using a domain field of type string.

Currently, the field is being managed from the view, but you can define it as a string field in the domain as follows:

<string name="totalExperience" title="Total Experience">
    <![CDATA[
        // Write your Java code here to process the value and return it
        return "";
    ]]>
</string>

By doing this, the value will be auto processed when the record is saved.

If you have any further questions or need additional clarification, please let me know. Thank you.

Best regards,

1 « J'aime »