简体   繁体   中英

How do I pass a JSON array from a text/javascript block to a runat=server block in exacttarget/salesforce marketing cloud?

I've got a page with two <script> blocks on it, one running locally, one running on the ExactTarget server:

<script type="text/javascript">
var results = localStorage.getItem('results');
var results = JSON.parse(results);
</script>

<script runat=server>
Platform.Load("Core","1");
Write(Stringify(results)); //this returns a 'null' value
var campaignsupdate = DataExtension.Init("0DB9904F-CE05-45E7-8052-    7C6935B4B012");
for(var i=0; i < results.length; i++) {
var rowid = results[i]["ROWID"];
var title = results[i]["title"];
campaignsupdate.Rows.Update({title: title},["ROWID"], [rowid]); 
}
</script>

At the moment, calling 'results' in the 'runat=server' block returns a null value. How do I access the 'results' array in the 'runat=server' block?

You can't. As the Server Side Java Script runs on the server :), it's executed prior to the javascript which is executed on the client machine, so the var 'results' does not exists when you access to it in the SSJS block. As far as I know SSJS can't communicate with javascript so you can't use javascript libraries or code written in a javascript block. As an alternative, you can pass a value in the GET/POST request and get it in SSJS. Have a look at: http://help.marketingcloud.com/en/documentation/exacttarget/content/server_side_javascript/server_side_javascript_syntax_guide/core_library_server_side_javascript_functions/utilities_server_side_javascript_functions/ Request Object and Functions Area

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM