RE: Passing a string to N/render via addCustomDataSource()

Hello,

I have created a custom FreeMarker email template in Netsuite using N/render. Currently, my code works fine when passing in a bunch of data using the following code:

renderer.addCustomDataSource({

format: render.DataSource.OBJECT,

alias: 'mydata',

data: {

message: context.request.parameters.message,

signature: context.request.parameters.signature,

employee: runtime.getCurrentUser(),

},

});

In my template, I have to access the data properties using the mydata object names as defined in render.addCustomDataSource() method: ${mydata.message} and ${mydata.signature}. I was wondering if there is a way to simply pass in a string data source instead of an object/JSON/XML value so I can access my variables directly as such: ${message} and ${signature}. It seems that the render.addCustomDataSource() method doesn’t allow string values to be passed, only objects, JSON and XML data.

I doubt what I’m attempting is possible. However, if anyone has any insight into this, it is greatly appreciated.

Christian Rookie Asked on August 7, 2020 in SuiteScript.
Add Comment
1 Answers

Hi Christian,

Have you tried?


alias: "message",

data: "Hello World"

I’m thinking that strictly speaking it’s valid JSON.

I haven’t got access to try it at the moment but let me know how you get on and any errors.

Thanks,

Chris

Intermediate Answered on August 8, 2020.

Thanks for the reply. Sadly, this does not work as Netsuite expects a string formatted as JSON. I tried using a string without a JSON key { “Hello world!!” }, however Netsuite just doesn’t want anything to do with strings (or regular variables for that matter) whatsoever.

It really seems that Netsuite only works with objects for the render.addCustomDataSource() method which is a real shame coming from a PHP MVC background where you could pass any type of data to a view. For now, I guess I will work with a global data object and just pass everything into that object.

on August 10, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.