JS object fields in expressions | Community
Skip to main content
Level 3
July 10, 2017
Solved

JS object fields in expressions

  • July 10, 2017
  • 2 replies
  • 2711 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Marcel_Szimonisz

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

2 replies

Marcel_Szimonisz
Community Advisor
Marcel_SzimoniszCommunity AdvisorAccepted solution
Community Advisor
July 15, 2017

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

Level 3
July 19, 2017

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