Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

JS object fields in expressions

eriku40433679
Level 3
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
MarcelSzimonisz
Correct answer by
Community Advisor
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
MarcelSzimonisz
Correct answer by
Community Advisor
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

eriku40433679
Level 3
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