I'm trying to use the render module, i would lik...
# suitescript
s
I'm trying to use the render module, i would like to load a new tab or print an HTML page/pdf which i get back from an API not sure if this is the correct module?
b
s
i cant generate a pdf of the response as there is some parsing that needs to be done
Copy code
var response = <http://https.post|https.post>({
 url: "<https://www.shipglobal.us/api/testshipmentprocess>",
 headers: {
   'Content-Type' : 'application/xml',
  'Accept': '*'
 },
 body:xmlDocument
});
   //parse response       
var xmlresponse = xml.Parser.fromString({
    text: response.body
  });
var labelnode = xml.XPath.select({
node: xmlresponse,
xpath: '//Label'
});
var decode = fromBase64(labelnode[0]["textContent"])
var renderer=render.create();
var invoicePdf = renderer.renderPdfToResponse({
response: decode
});
b
There are 2 ways to write output
One is to get a file object
s
i dont want it to fill up the file cabient
b
The other is to create a freemarker formatted xml string
I heavily recommend you divide your task into pieces and then merge them
Unless shipglobal is doing something very weird, they are not responding with a freemarker xml content
s
freemarker formatted xml string can you explain ?
b
s
in the above, the variable decode holds a string of html document
b
Html does not sound like freemarker xml
Therefore you are using the wrong option
s
why do a need freemaker if the html page is built already
b
Good, i have said that there are 2 options
One of which only works for freemarker
Therefore you should be trying the other option
s
ok so let me clarify, do use the render module or file module?
b
if you dont know, try both
if one cant do what you are trying to do, do the other one
s
im not understanding
b
you have 2 options
im not picking for you
decide which one you want to use
if you cant do it on the first one you try, do the second one
if neither works, come back for advice
s
in the above code i was trying to use the render module to open anew page for printing
b
beyond the point that your inputs to TemplateRenderer.renderPdfToResponse are not correct, my main point to you shall be that all the stuff with pdf only works with freemarker xml
if you are not working with freemarker xml, or are not generating freemarker xml with a template, you have the wrong approach
s
I understand NetSuite is a very different world than javascript which I am used to .so please understand I get very confused with all these modules and the docs are very confusing
if I'm not using freemaker then the file module is my only option?
b
keep in mind that I work off only what you give me
from what you have given me, especially with not knowing what your response looks like or what you want to do with it
it does not look like you should be using the N/render module
s
i have it working with the file module but it only saves to file cabinet is there a way to have it open new tab to print
b
and your code?
s
Copy code
var zplFile = file.create({
													name: "customerPrimary.pdf",
													fileType: file.Type.WEBAPPPAGE,
													contents: decode,
                                                    folder: 81708
																								});
												var fileId = zplFile.save();
b
go back to my first response for your options
s
ServerResponse.writeFile you mean the response of the external API ?
b
there were 3 links i gave
go through all 3 of them
s
i saw that but the response is not xml string
b
good, we have once again eliminated 1 of the potential links
that leaves 2 of them left
s
Copy code
TypeError: response.writeFile is not a function [at Object.beforeSubmit (/SuiteScripts/Shipglobal.js:224:11)]
b
good, we are now at the point where the first link to writeFile is inappropriate by itself, especially without context
s
im not sure why you feel the need to talk in riddles
b
we are now at the point where i emphasize
Use ... ServerResponse.writeFile ... from a suitelet's response
s
i don't have a suitelet
b
then you need to get one
s
i was not looking for that option and i understood that from the beginning
b
most of this conversation has been me telling you to do x or y
while you have been trying to do z
i eliminated one of the options for you based on what you shared, so really only x
s
so youy are saying it is impossible to work the other way
b
dont know what you are trying to do from what context
i didnt really ask since you dont have much choice
browsers handle files in certain ways, with the most straightforward path being returning the contents of the page as the response
suitelets are the only way to do that, especially with dynamically generated content
you also mentioned the response might be a html page to be displayed, which is once again, something you would do with a suitelet
s
thank you for your help but next time try to understand what i wanted
b
i stated upfront what you would need to do and in what context, I would have no way of knowing thats not what you wanted without you telling me so
s
all good
have you ever heard of being able to attach this html/pdf that the native print label would work
b
print labels work by printing the default print label transaction form and its associated template
which is freemarker based
s
on the IF if i click print label i get the integrated shipping label for ups,usps
b
dont choose an integrated shipping method
those print to their own shipping label
s
im not using it
i just want to copy the same behavior
b
make your own button
make the button open your suitelet
s
i did that already which prints the integrated shipping label and packing slip one after the other
i would like to use the same button and have logic if using ship global then ..
b
netsuite's printing functionality is linked to creating pdfs
if you want to add your custom shipping label to that list, you need to make new freemarker template for it
s
ok that would be a project for adiffrent day