How to convert Swedish personal number from 10 to 12 characters

This solution document describes how to convert a Swedish personal number from YYMMDD-XXXX format to YYYYMMDDXXXX.

This example will assume the following:

  • The request parameter username contains the source format of personal number
  • The converted personal number will be stored in the item property userPersonalNumber
<p>{
                "name": "PropertyAddValve",
                "config": {
                    "name": "pnr",
                    "value": "{{request.username}}”
                }
            },
            {
                "name": "PropertySubstringValve",
                "config": {
                    "source": "pnr",
                    "dest": "dob",
                    "begin_index": "0",
                    "end_index": "6"
                }
            },
            {
                "name": "PropertySubstringValve",
                "config": {
                    "source": "pnr",
                    "dest": "year",
                    "begin_index": "0",
                    "end_index": "2"
                }
            },
            {
                "name": "PropertySubstringValve",
                "config": {
                    "source": "pnr",
                    "dest": "number",
                    "begin_index": "7",
                    "end_index": "11"
                }
            },
            {
                "name": "PropertyAddDateTimeValve",
                "config": {
                    "name": "currentYear",
                    "format": "YY"
                }
            },
            {
                "name": "ScriptEvalValve",
                "config": {
                    "mime_type": "application/javascript",
                    "script": "var year = flow.items().get(0).getPropertyValue('year'); var currentYear = flow.items().get(0).getPropertyValue('currentYear'); if (year &gt; currentYear) { flow.items().get(0).replaceProperty('prefix', '19') } else { flow.items().get(0).replaceProperty('prefix','20')};"
                }
            },
            {
                "name": "PropertyAddValve",
                "config": {
                    "name": "userPersonalNumber",
                    "value": "{{item.prefix}}{{item.dob}}{{item.number}}"
                }
            },</p>
Click to copy