Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!

Correcting/replacing values captured in list eVar through custom code

Avatar

Level 2

Hello,

 

We have a list eVar configured to capture the web form's field level errors, like "first_name", "company_name" etc.., when they are triggered. With the recent development change, some of these field name values are started to capture as unique number which looks something like this "00n5000000wfov". 

 

Its because Dev had to change the hidden name of the inputs so that they would work with our salesforce systems. So, what used to be company_name for instance, is now 00n5000000wfov. And then any reporting/parsing of the data could probably be 'translated" that 00n5000000wfov to company_name.

 

Can anyone help on how i can replace/map the unique values to the actual field names, so the reporting is clean ?

 

Below is the custom code which i've tried but is not working:

 

s.list3=_satellite.getVar("form:formError");

var fieldMapping = {
'00n5000000wfov' : 'company name',
'00n4c000000d1rr' : 'test this replaced text',
'00n4c000000d1ru' : 'replaced with this text'
};

var capturedValue = _satellite.getVar('s.list3');
var replacedValue = fieldMapping[capturedValue] || capturedValue;
_satellite.setVar('s.list3', replacedValue);

 

Example of our list eVar the way it currently looks : "first_name:last_name:email:00n4c000000d1rr:company:employees:00n4c000000d1ru:00n4c000000d1rp:00n4c000000d1rs:00n4c000000d1rt:00n4c000000d1rq"

 

Any leads are much appreciated!

Thanks!

12 Replies

Avatar

Community Advisor and Adobe Champion

If the field names don't change, you could just use Classifications to map "00n5000000wfov" to "first_name"?

 

Classifications process every 4 to 6 hours, and are not included in Raw Data exports (if that is a concern)... but they are available in Workspace, Data Warehouse, Report Builder and the APIs.

 

If you really want to do this in Launch, can you explain what you want your eVar to look like, like what format you need.

 

I see you start with

s.list3=_satellite.getVar("form:formError");

 

What does this value look like before you start manipulating?

Avatar

Level 2

Thanks Jennifer! If i go with classification, dont i also need to copy paste the errors which are currently capturing correctly (highlighted) to the "form error (classified)" classification field? If that is the case, i would need to keep updating the values every time there are new set of errors,no ? Just for the context, we use this same form error event on all the other forms as well. but we just want to classify/map the values which belongs to one form, input names for all the other forms are fine. 

 

NorData_0-1705609842232.png

 

The current format of values being captured in s.list3 is as below :

"first_name:last_name:email:00n4c000000d1rr:company:employees:00n4c000000d1ru:00n4c000000d1rp:00n4c000000d1rs:00n4c000000d1rt:00n4c000000d1rq"

 

After replacing the below codes with the field names the desired output should look like below :

00n4c000000d1r = business_location

00n4c000000d1ru = contact_number

00n4c000000d1rp = postal_code

00n4c000000d1rs = member_details

00n4c000000d1rt = documents

00n4c000000d1rq = referral_details 

 

Desired output:

"first_name:last_name:email:business_location:company:employees:contact_number:postal_code:member_details:documents:referral_details"

Avatar

Community Advisor and Adobe Champion

Yes, and for the record, with such a relatively small list of items, you could also do the Classifications with the Rule Builder, rather than the Importer... it's a lot easier to review and make changes.

 

Ok, so if I am reading the above correctly.. some fields are still coming through fine, but others aren't, and this sample would be if every field in the form failed... but say if only "first_name" failed, then you would just pass "first_name", right?

 

 

So because list vars are really just a string, trying to map each value won't really work the way you intend it to... and while we could split the values into an array and do a loop, then join them all up again, you could just do this simple method:

 

var formErrors = _satellite.getVar("form:formError");

formErrors = formErrors.replace("00n4c000000d1r","business_location").replace("00n4c000000d1ru","contact_number").replace("00n4c000000d1rp","postal_code").replace("00n4c000000d1rs","member_details").replace("00n4c000000d1rt","documents").replace("00n4c000000d1rq","referral_details");

s.list3 = formErrors;

 

 

I assume you are adding this code into the Custom Code of the Set Variables action? Where the code is placed makes a big difference... 

Avatar

Level 2

@Jennifer_Dungan  

Hi Jennifer, Thank you for the reply! I tried the above code and i dont think my list 3 is being updated with the formErrors updated value. 

 

I've added the code mentioned by you in custom code block of the "Form Error Rule"

 

NorData_3-1706896643028.png

 

2: When I execute it, I'm still seeing the un-updated list. That is the list3 with values "00n4c000000d1rr" etc...,

 

NorData_1-1706896484339.png

 

 

3: I tried removing the list3 from below list Vars in rule,  since it was assigned through custom code. But, i still dont see any change in the output.

 

NorData_2-1706896484340.png

 

If i try this code on console, it works fine (please see below). I think the challenge im facing now is sending this updated list back to s.list3.

NorData_4-1706896824716.png

 

 

I believe the list3 variable is not being updated for some reason but couldn't find where im wrong. Would you able to please help?

Avatar

Community Advisor and Adobe Champion

Is your if statement passing?

 

You can try adding a bunch of console.logs into your script to help you debug:

 

if (_satellite.getVar('form: form name') == "something"){
   console.log("!!!!!!!!! If statement passed");

   var formErrors = _satellite.getVar('form: form error');

   console.log("!!!!!!!!! Form Error (before): " + formErrors);

    formErrors = formErrors.replace("00n4c000000d1r","business_location").replace("00n4c000000d1ru","contact_number").replace("00n4c000000d1rp","postal_code").replace("00n4c000000d1rs","member_details").replace("00n4c000000d1rt","documents").replace("00n4c000000d1rq","referral_details");

    console.log("!!!!!!!!! Form Error (after): " + formErrors);

    s.list3 = formErrors;
    console.log("!!!!!!!!! List3: " + s.list3);
}

 

 

However, this is WebSDK... I didn't realize that.. so this extension is mapping the value to the XDM Stream, which I don't know if this does in custom code (I'm not on WebSDK yet, so I've not tried this... I do this in the old Client Side Analytics, but this might change here...

 

What you can try, is moving all this code to a new "Custom Code" Data Element, something like "form: processed form errors" and pass that into List3?

Avatar

Level 2

@Jennifer_Dungan  YEs, I guess you are right! Looks like i cant access s.list3 directly becasue of Web SDK. Please see below: 

NorData_0-1706898730036.png

 

I guess i would to try creating a custom code data element and use that to pass it to list 3. 

 

Avatar

Community Advisor and Adobe Champion

Sorry about that.. With so many people now on WebSDK, I really should ask, since it makes a big difference how things work

Avatar

Level 2

@Jennifer_Dungan  Yeah, i tried passing the custom code data element directly to list3 but the list3 is just returning empty. Can I still use Classification rule builder to get this fixed? Would you please give me steps on how to use it please?

Avatar

Community Advisor and Adobe Champion

Sure I can help with the Classification Rule... but one question, can you see if your Data Element is properly populated when the rule is run?

 

You could add a simple:

 

console.log(_satellite.getVar('form: processed form errors'));

 

in the custom code of the rule.. just to make sure that the Data Element is actually working?

 

 

Now, for classifications, if you go that route.

Your list item as a whole looks like this:

first_name:last_name:email:00n4c000000d1rr:company:employees:00n4c000000d1ru:00n4c000000d1rp:00n4c000000d1rs:00n4c000000d1rt:00n4c000000d1rq

The List should split these based on the colon, so:

  • first_name
  • last_name
  • email
  • 00n4c000000d1rr
  • company
  • employees
  • 00n4c000000d1ru
  • 00n4c000000d1rp
  • 00n4c000000d1rs
  • 00n4c000000d1rt
  • 00n4c000000d1rq

 

So you if you create one classification on your list:

Admin > Report Suites
(Choose Suite or multiple Suites - it's easiest to do Prod and Dev, etc together)

Edit Settings > Conversions > Conversion Classifications

 

Choose your list item from the list (it won't say list, like the others say eVar, but lists should be near the top of the list)

 

Then Add a Classification:

Jennifer_Dungan_0-1706920138849.png

 

Give it a name and a description:

Jennifer_Dungan_1-1706920167803.png

 

 

Now, you can go to Admin > Classification Rule Builder

 

Add a Rule Set, and give it a name:

Jennifer_Dungan_2-1706920249340.png

 

Select the Report Suite and Variables:

Jennifer_Dungan_3-1706920308021.png

 

Choose all the suites where you created the classification, and choose your list dimension.

 

Now, you can proceed to Add Rules... since these don't require fancy Regex, you can just do literal contains, and put in the value you want to change it to:

 

Jennifer_Dungan_4-1706920533129.png

 

Choose your Classification, and put the value you want as text in the "to" column.

 

Put all the specific mappings first, then to make your life easier, add 1 regex catchall at the end of the rules:

 

Jennifer_Dungan_5-1706920699139.png

 

 

The Regex is .*

and the Value should be $0

 

This will catch the values that are already populated like "first_name", and add it to the Classification as is... so you only have to use the Classification for your Report instead of mixing the raw and classified data....

 

Also, any new values that aren't mapped will come through and you will be able to see what needs new mapping rules.

Avatar

Level 2

@Jennifer_Dungan Thank you! I've created the below classification rule. but the data is not getting classified. I checked the data after 24 hours. Can you please help me find mistakes in my classification?

 

NorData_1-1707234467930.png

NorData_2-1707234491434.png

NorData_0-1707235801748.png

 

 

Avatar

Community Advisor and Adobe Champion

Can you copy the data from your Report and use the "Test Rule Set" to see what might be happening?

 

It looks like all the "contains" rules are failing, and only the catchall is working... 

 

We might just convert all those rules over to Regex and see if that works better?

 

You should just be able to change from "Contains" to "Regular Expression" and leave the "Match Criteria" the same...

 

Use the Test Rules to check that these are actually matching.

Avatar

Level 2

@Jennifer_DunganI just changed it to regex and tested the rules to see if its working. Looks like it is not classifying at all. I tried with both "contains" and "regex"

 

NorData_0-1707246857622.png

NorData_1-1707246923283.png