Expand my Community achievements bar.

SOLVED

JS object fields in expressions

Avatar

Level 3

Hi all,

I'm building a lookup javascript object whose values I want to use in an enrichment activity as a calculated field. Here's an example of what i want to happen

Variable:

instance.vars.variableA={key:'value'};

---

Expression

$(instance/vars/@variableA[@columnFromTargetingDimension])

Hope I'm making sense. I need to read the associated value from the javascript object based on a field from the targeting dimension but i'm having problems with the syntax or if this is possible in the first place. I'm also open to other approaches as well except for enumerations for reasons I won't get into.

Thanks,

--Erik

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello Erik,

"The variables are the free properties of the instance, task and event objects. The JavaScript types authorized for these variables are string, number and Date"

So you cannot save other than date,number or string object in to the instance variable.

But you might try SQL activity where you save your object to json string in the advanced tab

var variableA = {label:"auto",field:"sLabel"};

//to string

instance.vars.variableA = JSON.stringify(variableA);

And then nicely put back to object in the SQL activity

<%

  var variableA = JSON.parse(instance.vars.variableA);

%>

INSERT INTO <%= vars.tableName %> (<%= variableA.field %>) SELECT <%= variableA.field %> FROM XtkWorkflow where <%= variableA.field %> LIKE '%<%= variableA.label %>%'

But how you do the rest I do not know....good luck

Marcel

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hello Erik,

"The variables are the free properties of the instance, task and event objects. The JavaScript types authorized for these variables are string, number and Date"

So you cannot save other than date,number or string object in to the instance variable.

But you might try SQL activity where you save your object to json string in the advanced tab

var variableA = {label:"auto",field:"sLabel"};

//to string

instance.vars.variableA = JSON.stringify(variableA);

And then nicely put back to object in the SQL activity

<%

  var variableA = JSON.parse(instance.vars.variableA);

%>

INSERT INTO <%= vars.tableName %> (<%= variableA.field %>) SELECT <%= variableA.field %> FROM XtkWorkflow where <%= variableA.field %> LIKE '%<%= variableA.label %>%'

But how you do the rest I do not know....good luck

Marcel

Avatar

Level 3

Ahh. That's why. I've gone a different route to solve my problem but this is good to keep in mind for future implementations. Thanks for the help Marcel.

Cheers!

--Erik