Expand my Community achievements bar.

SOLVED

getOption() in JS code

Avatar

Level 3

Hi all,

 

We are using Javascript code for sms delivery. The URL used in the script is different for development and production. So I am planning to save the URL in option and this will be called in JS code using getOption(). When triggering sms delivery using the Javascript Iam getting below error

 

" getOption is not defined"

 

Same code I tried in Workflow using javascript activity, I can able see the option value in logInfo().

 

Could you please tell me what will be the issue.

 

Thanks,

Ram 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ramprakasht3196

include these libraries on the script beginning and try again.

loadLibrary("xtk:shared/nl.js");
loadLibrary("xtk:shared/xtk.js");
loadLibrary("xtk:shared/json2.js");
loadLibrary("xtk:common.js");

Regards,

Milan

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @ramprakasht3196

include these libraries on the script beginning and try again.

loadLibrary("xtk:shared/nl.js");
loadLibrary("xtk:shared/xtk.js");
loadLibrary("xtk:shared/json2.js");
loadLibrary("xtk:common.js");

Regards,

Milan

 

 

Avatar

Level 3

Hi @Milan_Vucetic 

Thanks for your response.

I added the libraries. But still error exists. Is there any alternative to call Option?

 

Thanks,

Ram

Avatar

Community Advisor

Hi @ramprakasht3196, this is really weird.

If you use JS in workflow or JS connector this must work: getOption('name_of_an_option') . If you are working with delivery templates or personalization blocks the use this: <%@ include option='name_of_an_option' %> . If you speak about JS connector and added these libraries and have MTA server separated from app server, you must restart MTA in order to use latest version of JS.

Regards,
Milan

Avatar

Community Advisor

Hi @ramprakasht3196,

 

You cannot use option variables inside your SMS delivery as the MTA does not get the options from your marketing instance, and also does not support the GetOption() method.

You will need to read the option variable in a js activitiy prior to the SMS delivery, or in the initialisation script of your SMS delivery activity as something like this:

var.thisOption = getOption("readMyValue"); //readMyValue is an example option variable name

 

Then use it in your SMS delivery activity as you want it: <%= vars.thisOption %>

 

Thanks,

Ishan