Expand my Community achievements bar.

SOLVED

Storing multiple datalayer 'user form validation error' array values in a prop with DTM

Avatar

Level 1

Hello, can anyone help me to return a list of error messages that are stored in a data layer array please?

I’m an analyst with a marketing background so please forgive any developer language faux pas…

Background

We’ve set up a data layer for business and form validation error messages. I'm able to capture and return a specific data layer array error message with the following DDL path:

digitalJSONdata.validationErrors[0].message;

I have managed to set up a data element that returns the array value like this (triggered by a data element changed EBR):

if (digitalJSONdata && digitalJSONdata.validationErrors) { return digitalJSONdata.validationErrors[0].message; } return ;

How to capture any error array messages

I'd like to grab any error message that is caused by the user not completing the form completely, not just the one message shown in my example above at .validationErrors[0].message and store them in Prop1. Can anyone help me to write the custom script that returns the text strings for all of the array validation error messages that are returned please, or point me in the right direction?

I’ve attached an example that shows the 23 error arrays & objects on the first page of our form.

And a screen grab that shows the ddl from page source with errors triggered to help set the scene:

Any guidance or support is gratefully received.

Rik

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Rik,

 In the Data Element custom code you could do “return dataLayer.ValidatiohError” (which returns your array), then call it with “_satellite.getVar(‘ValidationError’)[0]”. That way you can easily access any of the array values using just a single Data Element by changing the number in the call

Thanks & Regards

Parit Mittal

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi Rik,

 In the Data Element custom code you could do “return dataLayer.ValidatiohError” (which returns your array), then call it with “_satellite.getVar(‘ValidationError’)[0]”. That way you can easily access any of the array values using just a single Data Element by changing the number in the call

Thanks & Regards

Parit Mittal

Avatar

Level 1

Thanks for your response, Parit =)