oldValue update

Hi! I’ve been trying to get the last previous value of an attribute. So, if there was a modification from values “X01” to “X02” and finally “X03”, i always need to read the n-1 previous value, that would be “X02” here.

I tried using this transform, but i always get the first value there was in this attribute, for example X01. Code attached. Any idea? Thanks!

{
  "attributes": {
    "values": [
      "$oldValue",
      {
        "attributes": {
          "sourceName": "Mock-SAIP",
          "attributeName": "storeID"
        },
        "type": "accountAttribute"
      }
    ]
  },
  "type": "firstValid",
  "name": "oldValue firstValid"
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

Hi @gsierra ,

Try this step-by-step,

See whether the oldValue prints.

{
  "type": "static",
  "attributes": {
    "value": "$oldValue"
  }
}

If this is populated, check the below:

{
  "type": "firstValid",
  "attributes": {
    "values": [
      "$oldValue",
      "no oldValue"
    ]
  }
}

If these works, then there might be some issue in the accountAttribute part.

"attributes": {
    "ignoreErrors": "true",
    "values": [
        "$oldValue",
        {
            "attributes": {
                "attributeName": "abcd",
                "sourceName": "test"
            },
            "type": "accountAttribute"
        },
        "no value"
    ]
},
"type": "firstValid"

Try this.

The transform is set up to do the following:

  1. First, it tries to return $oldValue, which represents the attribute’s previous value.

  2. If $oldValue is null, it then attempts to retrieve the “abcd” attribute from the “test” source.

  3. If both of the above are null, it returns the static value “no value”.

Issue here is it $oldValue will always be the first none null value and will never be updated after that. So in the case where source attribute values change from “X01” to “X02” and finally “X03”, the $oldValue will forever be “X01” (for this transform)

You can try the below transform which returns old value when account attribute is not empty/null and both new and old values are not equal, otherwise it returns new value.

  {
        "name": "Old Value Test",
        "type": "static",
        "attributes": {
            "currentValue": {
                "attributes": {
                    "ignoreErrors": "true",
                    "values": [
                        {
                            "attributes": {
                                "attributeName": "storeID",
                                "sourceName": "Mock-SAIP"
                            },
                            "type": "accountAttribute"
                        },
                        "none"
                    ]
                },
                "type": "firstValid"
            },
            "previousValue": {
                "attributes": {
                    "ignoreErrors": "true",
                    "values": [
                        {
                            "attributes": {
                                "value": "${oldValue}"
                            },
                            "type": "static"
                        },
                        "none"
                    ]
                },
                "type": "firstValid"
            },
            "value": "#if ($currentValue != 'none' && $currentValue != $previousValue)$previousValue#{else}$currentValue#{end}"
        },
        "internal": false
    }