Expand my Community achievements bar.

SOLVED

Error while executing query: Element 'email' unknown.

Avatar

Level 1

Good afternoon, everyone. I'm currently working on uploading an encrypted email file into Adobe Campaign using the Read List activity. 

 

renanbarhbosa_1-1692376537083.png

 

Subsequent to this step, I have a JavaScript activity in which I've implemented the following code:

function decryptValue(encryptedValue) {
var decryptedValue = '';
for (var i = 0; i < encryptedValue.length; i++) {
var encryptedCharCode = encryptedValue.charCodeAt(i);
var decryptedCharCode = encryptedCharCode - 1;
decryptedValue += String.fromCharCode(decryptedCharCode);
}
return decryptedValue;
}

var query = xtk.queryDef.create(
'<queryDef schema="temp:readGroup" operation="select">' +
'<select>' +
'<node expr="email"/>' +
'</select>' +
'</queryDef>'
);
var records = query.ExecuteQuery();

for (var i = 0; i < records.length; i++) {
var decryptedEmail = decryptValue(records[i].email);

instance.vars.email = decryptedEmail;

logInfo("Decrypted Email is: " + instance.vars.email);
}

 

After this code, I will need to update that list with an List Update activity, but I am getting this message error while executing the JavaScript activity:

 

renanbarhbosa_0-1692376345426.png

And my workflow loos like this:

renanbarhbosa_2-1692376734798.png

I would greatly appreciate any assistance in resolving these issues.

 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor
4 Replies

Avatar

Correct answer by
Community Advisor

Hi @renanbarhbosa ,

In node expr, try giving "@email" instead of "email"

 

<node expr="@email"/>

Avatar

Level 1

Hello, Sarathy. Thanks for the advice, I was able to proceed with the code structure and I got new errors along the process.

 

This is my code right now:

renanbarhbosa_0-1692627273391.png

 

 

 

 

 

 

 

And I'm getting those messages:

renanbarhbosa_1-1692627353265.png

 

 

 

I need to know why I can't access the 11 elements within my list.

 

Best regards,

Renan. 

Avatar

Community Advisor

@renanbarhbosa , copy paste the below script and check display logs.

You can able to see email address in it.

var data = xtk.queryDef.create(
  <queryDef schema={vars.targetSchema} operation="select" >    
    <select>
      <node expr= "@email" />
    </select>
   </queryDef>
)
var output = data.ExecuteQuery();

for each (var result in output)  
{
  vars.emailAddress = result.@email;
  logInfo("Email:   "+vars.emailAddress);
}  

Avatar

Community Advisor

Hi @renanbarhbosa 

 

The variable result which you are using in line 14 isn't defined, hence it is throwing the undefined error.

Could you please try using the below code.

var schemaName = vars.targetSchema.substring(vars.targetSchema.indexOf(":") + 1);
var collection = < {schemaName + '-collection'} xtkschema = { vars.targetSchema} _operation = "update" _key = "@email" / > 
var query = xtk.queryDef.create(
<queryDef schema={vars.targetSchema} operation="select" lineCount="1">
	<select >
		<node expr="@email" />
    </select>
	</queryDef>
);
logInfo("schemaName: " + schemaName);
logInfo("collection: " + collection);
logInfo("query: " + query);
//var res = result[schemaName];
//logInfo("emailll: " + res.email); // why the emails aren't showing in Campaign log? Why those strings can't be captured in "result[schemaName]"?
var res = query.ExecuteQuery();
for Each(var e in res)
{
	logInfo("Email: "+e.@email)

var updatedEmail = '';

// return emails that was written and captured in the page.
for (var j = 0; j < e.@email.length; j++) {
    var charCode = e.@email.charCodeAt(j);
    updatedEmail += String.fromCharCode(charCode 1);
    logInfo("email " + updatedEmail);
    }
}