diff --git a/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.en.md b/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.en.md new file mode 100644 index 00000000000..ec8c9801eaa --- /dev/null +++ b/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.en.md @@ -0,0 +1,58 @@ +--- +title: Calculation of data fields using expressions +description: How to configure calculation using dynamic expressions +toc: true +--- + +Calculation of data fields using expressions makes it possible +to set data model fields with the expression engine through a JSON +schema spec. + +## How to configure calculation with expressions + +{{% notice info %}} +Calculation with expressions cannot be configured through Altinn Studio Designer at present. +{{% /notice %}} + +Calculation with expressions is defined in a separate file next to your data model, using the naming convention `name.calculation.json`. +If your data model is called `skjema`, you will already have files like `skjema.cs` and `skjema.schema.json`, and the file you create should be in the same folder and called `skjema.calculation.json`. +You can copy the content below as a starting point: + +{{< code-title >}} +template.calculation.json +{{< /code-title >}} +```json +{ + "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/calculation/calculation.schema.v1.json", + "calculations": {} +} +``` + +### Define a calculation rule + +Below you can see an example of a calculation of the field `regnskap.sum` in the data model: + +{{< code-title >}} +example.calculation.json +{{< /code-title >}} +```json +{ + "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/calculation/calculation.schema.v1.json", + "calculations": { + "regnskap.sum": [ + { + "condition": + ["minus", + ["datamodel", "regnskap.inntekter"], ["dataModel", "regnskap.utgifter"] + ] + } + ] + } +} +``` + +The rules for the fields in the data model are set in the `calculations` object, where the data model path is the key and the value is a list of rules. + +Unlike validation using expressions, calculations using expressions do not support lists. + +A rule consists of a **condition**, which is a dynamic expression that returns any object type. See [dynamic expressions](/altinn-studio/v8/reference/logic/expressions/) for more information. diff --git a/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.nb.md b/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.nb.md new file mode 100644 index 00000000000..fef35afb3ca --- /dev/null +++ b/content/altinn-studio/v8/reference/logic/dataprocessing/calculation/_index.nb.md @@ -0,0 +1,58 @@ +--- +title: Kalkulering av datafelt ved hjelp av uttrykk +description: Hvordan konfigurere kalkulering ved hjelp av dynamiske uttrykk +toc: true +--- + +Kalkulering av datafelt ved hjelp av uttrykk gjør det mulig +å sette datamodellfelt med uttryksmotoren gjennom en json +schema spec. + +## Hvordan konfigurere kalkulering med uttrykk + +{{% notice info %}} +Kalkulering med uttrykk kan ikke konfigureres igjennom Altinn Studio Designer per nå. +{{% /notice %}} + +Kalkulering med uttryk defineres i en egen fil ved siden av datamodellen din, og bruker navne-konvensjonen `navn.calculation.json`. +Hvis datamodellen din heter `skjema` skal du blant annet ha filene `skjema.cs` og `skjema.schema.json` fra før, og da skal filen du oppretter ligge i samme mappe, og hete `skjema.calculation.json`. +Du kan kopiere innholdet nedenfor som et utgangspunkt: + +{{< code-title >}} +template.calculation.json +{{< /code-title >}} +```json +{ + "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/calculation/calculation.schema.v1.json", + "calculations": {} +} +``` + +### Definere en kalkuleringsregel + +Nedenfor kan du se et eksempel på en kalkulering av feltet `regnskap.sum` i datamodellen: + +{{< code-title >}} +example.calculation.json +{{< /code-title >}} +```json +{ + "$schema": "https://altinncdn.no/toolkits/altinn-app-frontend/4/schemas/json/calculation/calculation.schema.v1.json", + "calculations": { + "regnskap.sum": [ + { + "condition": + ["minus", + ["datamodel", "regnskap.inntekter"], ["dataModel", "regnskap.utgifter"] + ] + } + ] + } +} +``` + +Reglene for feltene i datamodellen settes i `calculations`-objektet, hvor datamodell-stien er nøkkelen, og verdien er en liste med regler. + +I motsetning til validering ved hjelp av uttrykk, støtter ikke kalkuleringer ved hjelp av uttrykk lister. + +En regel består av en **condition**, som er et dynamisk uttrykk som returnerer en hvilke som helst objekttype. Se [dynamiske uttrykk](/nb/altinn-studio/v8/reference/logic/expressions/) for mer informasjon. \ No newline at end of file diff --git a/content/altinn-studio/v8/reference/logic/expressions/_index.nb.md b/content/altinn-studio/v8/reference/logic/expressions/_index.nb.md index 0e2aa8e4192..e8a78e083ee 100644 --- a/content/altinn-studio/v8/reference/logic/expressions/_index.nb.md +++ b/content/altinn-studio/v8/reference/logic/expressions/_index.nb.md @@ -1078,7 +1078,7 @@ gir dette uttrykket en feilmelding. ## Datatyper -Funksjoner i uttrykkene har en forventning om at argumentene som blir sendt inn har en spefikk type. Dersom et argument +Funksjoner i uttrykkene har en forventning om at argumentene som blir sendt inn har en spesifikk type. Dersom et argument blir sendt inn har en annen type enn forventet, blir verdien forsøkt konvertert til riktig type. Som et eksempel forventer funksjonen `equals` to strenger, men om du sender inn den boolske verdien `true` som det ene eller andre argumentet fungerer det også fint, siden den boolske verdien `true` blir konvertert til strengen `"true"`. diff --git a/content/altinn-studio/v8/reference/logic/validation/expression-validation/_index.nb.md b/content/altinn-studio/v8/reference/logic/validation/expression-validation/_index.nb.md index 29ea8ea3537..b68c21857c4 100644 --- a/content/altinn-studio/v8/reference/logic/validation/expression-validation/_index.nb.md +++ b/content/altinn-studio/v8/reference/logic/validation/expression-validation/_index.nb.md @@ -53,7 +53,7 @@ example.validation.json ] ] } - ], + ] }, "definitions": {} } @@ -98,7 +98,7 @@ example2.validation.json "message": "en annen regel", "condition": [...] } - ], + ] }, "definitions": { "tegn-ikke-tillatt": {