``` renderer.addCustomDataSource({ form...
# suitescript
s
Copy code
renderer.addCustomDataSource({
        format: render.DataSource.OBJECT,
        alias: "results",
        data: {results: [{custrecord_lpn_parent : 'LPN00000001'}]}
    });
c
Copy code
renderer.addCustomDataSource({
        format: render.DataSource.JSON,
        alias: "results",
        data: {results: [{custrecord_lpn_parent : 'LPN00000001'}]}
    });
try changing from OBJECT -> JSON in render.DataSource
SuiteAnswer: 63092 also is a decent example
e
Template referencing
view
custom datasource
script creating custom data source
endTime
and
runTime
end up just being a string/number, respectively, so nothing complicated there
s
@creece, I tried that but its the same issue. If you use JSON instead of OBJECT, the only difference is that the value provided needs to be a JSON string vs an object
@erictgrubaugh, that works when every thing is a JSON object, but what I need is to be able to populate an array called “results”, but the only way to populate an array that way would be to use “addSearchResults”, but that requires an array of Search.Result, which I can only create by running a saved search.
I think what I might try is passing in another variable, and then adding a condition at the top of the template to check for that value and when its present, then populate the “results” array
e
Why is the only way to populate an array called
results
with
addSearchResults
?
Copy code
let searchResults = s.load(...).run().getRange(...);
let objectResults = searchResults.map((result) => ({
  entity: result.getValue({name: "entity"}),
  email: result.getValue({name: "email"}),
  // ... other fields from the result
});

renderer.addCustomDataSource({
  format: render.DataSource.OBJECT,
  alias: "results",
  data: objectResults
});
Take the Array of
Result
instances,
map
them to Objects instead, then use the Array of Objects as your data source
s
in your example you basically have this correct?
Copy code
renderer.addCustomDataSource({
        format: render.DataSource.OBJECT,
        alias: "results",
        data: [{entity: 'A', email: '<mailto:a@mail.com|a@mail.com>'}, {entity: 'B', email: '<mailto:b@mail.com|b@mail.com>'}]
    });
e
yep
s
when you use an OBJECT datasource, the data property has to be an object, not an array
{“type”“error.SuiteScriptError”,“name”“UNSUPPORTED_DATA_FORMAT”,“message”:“You have supplied an invalid value for data format: JSON: A JSONObject text must begin with ‘{’ at 1 [character 2 line 1]“,”stack”:[“addCustomDataSource(N/render.js)“,”<anonymous>(adhoc$-1$debugger.user:31)“,”<anonymous>(adhoc$-1$debugger.user:1)“],“cause”{“type”“internal error”,“code”“UNSUPPORTED DATA FORMAT”,“details”“You have supplied an invalid value for data format: JSON: A JSONObject text must begin with ‘{’ at 1 [character 2 line 1]“,”userEvent”null,“stackTrace”[“addCustomDataSource(N/render.js)“,”<anonymous>(adhoc$-1$debugger.user:31)“,”<anonymous>(adhoc$-1$debugger.user:1)“],“notifyOff”false},“id”“”,“notifyOff”false,“userFacing”false}
e
but that structure was generated from Search Result instances
s
so to make it work, your data would have to be
Copy code
{results: [{entity: 'A', email: '<mailto:a@mail.com|a@mail.com>'}, {entity: 'B', email: '<mailto:b@mail.com|b@mail.com>'}]}
and since alias is required, the template would have to be updated to reference it as alias.results, which is fine, but then you cant use the same template to print from the search results in the UI
e
OK then make it an object that contains a property with the array:
Copy code
{
  format: OBJECT,
  alias: "mySearch",
  data: { results: [{...}, {...}, {...}]
}
with
Copy code
<#list mySearch.results as result>
yep you got it
s
so what I ended up doing was adding this to the header of the template
Copy code
<#if json?has_content>
        <#assign results = json.results>
    </#if>
e
Without digging in to the docs or source of
addSearchResults
to understand how it handles summaries, I don't know what else you can do
s
now the template works for both