Hi folks, I am coding a User Event Script to rende...
# suitescript
g
Hi folks, I am coding a User Event Script to render a PDF that is created in a Suitelet Script. I am using resolveScript to get the URL and then to call the script to get its response, the body response is as follows: myServerResponseObj = _"<!DOCTYPE html>\n<html>\n\n<head>\n<title>Notice</title>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n\n \t<script type='text/javascript' src='/javascript/FieldLevelHelp.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' src='/assets/help_service/3663278969.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/ui/jquery/jquery-3.5.1.min.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/ui/jquery/jquery_isolation.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/javascript/NLUtil.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' src='/javascript/NLUtil.js?NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' src='/javascript/NLUIWidgets.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' src='/assets/legacy_widgets/2249544138.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/assets/help_center_service/3696101135.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/assets/legacy_apputil/3709065897.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' src='/javascript/NLAppUtil.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' src='/uirefresh/script/global.js__NS_VER=2022.2&minver=15.nlqs?NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n<link rel='stylesheet' href='/core/styles/pagestyles.nl?ct=-2&bglt=F2F4F6&bgmd=EDF1F7&bgdk=737A82&bgon=5C7499&bgoff=AFB5BF&bgbar=5C7499&tasktitletext=E4EAF4&crumbtext=C4C8CF&headertext=B5C1D5&ontab=FFFFFF&offtab=000000&text=000000&link=000000&bgbody=FFFFFF&bghead=FFFFFF&portlet=C0CAD9&portletlabel=000000&bgbutton=FFE599&bgrequiredfld=FFFFE5&font=Verdana%2CHelvetica%2Csans-serif&size_site_content=9pt&size_site_title=9pt&size=1.0&nlinputstyles=T&accessibility=F&appOnly=F&NS_VER=2022.2'><link rel='stylesheet' type='text/css' href='/uirefresh/css/button.css' />\n</head>\n\n<body bgcolor='#FFFFFF' link='#000000' vlink='#000000' alink='#330099' text='#000000' topmargin='0' marginheight='1' onload='page_init()' class='error-page'>\n<img class='uir-logo' src='/images/logos/netsuite-oracle.svg' border=0 style='margin-right30px;margin left10px;'>\n<table border=0 cellPadding=0 cellSpacing=0 width=100%>\n\n<tr><td class='bglt'>\n<table border='0' cellspacing='0' cellpadding='5' width='100%'>\n<tr><td class='textboldnolink'>Notice</td></tr>\n<tr><td vAlign='top'>\n<table border='0' cellspacing='0' cellpadding='0' width='100%'>\n<tr><td class='text'> </td></tr>\n\n<tr><td class=text><img src='/images/5square.gif' width=5 height=5>You are not allowed to navigate directly to this page.</td></tr>\n\n<tr><td class='text'> </td></tr>\n<tr><td class='text'> </td></tr>\n</table></td></tr></table></td></tr>\n<tr><td><span id='tbl_login'><INPUT type='button' class='bgbutton' style='' value='Log In Again' id='login' name='login' onclick=\"document.location.href='/pages/login.jsp'; return false;\"></span></td></tr>\n</table>\n\n<script language='JavaScript' type='text/javascript'>\nfunction page_init() {\n}\n</script>\n\n</body>\n</html>\n"_ Then I use the renderPdfToResponse function to render the PDF, but it seems it is not working. See the snippet below:
Copy code
function renderPDF(scriptId, deployId, fulfillmentId){
        log.debug("renderPDF", "*** START ***");
        try{
          var stURLSuitelet = url.resolveScript({
            scriptId: scriptId,
            deploymentId: deployId,
            params: {
                pid: fulfillmentId
            },
            returnExternalUrl: true
          });
          log.debug("renderPDF", "stURLSuitelet = " + stURLSuitelet);
    
          var myServerResponseObj = https.get({
            url: stURLSuitelet
          });
          log.debug("renderPDF", "myServerResponseObj = " + JSON.stringify(myServerResponseObj.body));

          var renderer = render.create();
          var fileObj = renderer.renderPdfToResponse({
            response: myServerResponseObj.body
          });

          log.debug("renderPDF", "fileObj = " + fileObj);
    
          return fileObj;
        } catch (e) {
          log.error({
          title: "renderPDF: Error to create the PDF",
          details: JSON.stringify(e)
          });
        }
      }
Do you know what is wrong with my script?
r
The server response is telling you that
You are not allowed to navigate directly to this page.
Posting the message instead of the HTML would be more helpful so people don't have to render your HTML.
Often times this has to do with whether or not the user/role has access to the suitelet, or whether or not the suitelet deployment is set to available without login.
s
there are new APIs for invoking Suitelets/Restlets from server scripts. I don't remember the function names off the top but that may be what you want
👍🏻 1
r
@Shawn Talbert I would be interested to see those APIs. I've seen kind of a hacky way of doing this but I usually use a client script.
e
https.requestRestlet()
mindblow 1
b
the page you are seeing is what happens when you try to access the external url of a suitelet that is not available externally
s
actually, looks this those APIs are for RESTlet and REST web services only, not Suitelets?
b
the quick fix is making the suitelet available without login, which will essentially make your fulfillment data public
thats usually not desirable
instead, you want to use redirect.toSuitelet to redirect to your suitelet
g
Hi guys, I just changed the way to call the Suitelet and this is the response: _*myServerResponseObj* = "<!doctype html>\n\n<html>\n<head>\n\t<title>NetSuite Login</title>\n\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link rel='stylesheet' href='/core/styles/pagestyles.nl?ct=-2&bglt=F2F4F6&bgmd=EDF1F7&bgdk=737A82&bgon=5C7499&bgoff=AFB5BF&bgbar=5C7499&tasktitletext=E4EAF4&crumbtext=C4C8CF&headertext=B5C1D5&ontab=FFFFFF&offtab=000000&text=000000&link=000000&bgbody=FFFFFF&bghead=FFFFFF&portlet=C0CAD9&portletlabel=000000&bgbutton=FFE599&bgrequiredfld=FFFFE5&font=Verdana%2CHelvetica%2Csans-serif&size_site_content=9pt&size_site_title=9pt&size=1.0&nlinputstyles=T&accessibility=F&appOnly=F&NS_VER=2022.2'>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/loginpage_commonlook/3423769072.css?NS_VER=2022.2&minver=15\" />\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/javascript/FieldLevelHelp.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/assets/help_service/3663278969.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/ui/jquery/jquery-3.5.1.min.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/ui/jquery/jquery_isolation.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/javascript/NLUtil.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/javascript/NLUtil.js?NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/assets/help_center_service/3696101135.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/assets/legacy_apputil/3709065897.js?NS_VER=2022.2&minver=15'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/javascript/NLAppUtil.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/javascript/NLPortal.jsp?JSP_VER=1&NS_VER=2022.2&minver=15&buildver=30671'></script>\r\n \t<script type='text/javascript' nonce=\"4wXQz5DBIFblpXlsnEOAWgH/dNIVimJiGaAV2i/uwMc=\" src='/assets/loginpage_defaultloginpage/1863214813.js?NS_VER=2022.2&minver=15'></script>\r\n\n\n</head>\n<body>\n\n<div id=\"page-wrapper\">\n\t<div id='div__alert' class=\"text-align: center\"></div>\n<div class=\"page-header flex-center-vertically\">\n\t<div class=\"container\">\n\t\t<a href=\"http://www.netsuite.com/portal/home.shtml?noredirect=T\" tabindex=\"-1\">\n\t\t\t<img src=\"/authentication/ui/loginpage/assets/images/orale-netsuite-white-logo.svg\" alt=\"Oracle NetSuite\"\n\t\t\t\t height=\"20\"/> <!-- THIS WILL BE LOGO -->\n\t\t</a>\n\t</div>\n\n</div> <!-- END HEADER -->\n\n<div class=\"page-content container\" style=\"margin-bottom: 40px\">\n\t<div class=\"page-content-main-row text-center content-center\">\n\n\t\t<div class=\"box login-box text-left\" id=\"login-form\">\n\t\t\t<div class=\"login-header\">\n\t\t\t\t<h2 class=\"login-box-title title\">Log In</h2>\n\t\t\t\t\t<img src=\"/images/logos/netsuite-oracle.svg\" alt=\"Company logo\" align=\"center\" id=\"login-logo\" class=\"logo-img\">\n\t\t\t</div>\n\t\t\t<div class=\"box-body\">\n\t\t\t\t<form method=\"post\" id=\"login-form\">\n\t\t\t\t\t\t<input type=\"hidden\" name=\"redirect\" value=\"/app/site/hosting/scriptlet.nl?script=360&deploy=1&compid=646033_SB2&pid_ But the PDF is not rendered yet, I need to send that PDF file by email 😞
r
Show the entry point function for the UE.
It's unclear whether you're using a button or how you're trying to implement this.
b
same basic problem as the last thing you shared, this is not a pdf, its html
you havent shared all of the html, but this one is probably a login page
r
This is a common design pattern if you don't want the suitelet to be available without login.
g
@reptar it is an After Submit entry point, the script should email the packing list to some customer's contacts once the fulfillment is set to shipped.
r
are you not able to only use an afterSubmit UE to do that? printing a PDF and sending an email sounds like it would be within governance
b
the internal url of a suitelet requires a session cookie to access it, primarily so that only logged in users can use it
serverside scripts dont have that cookie, its stored in the browser
the external url of a suitelet is accessible from a serverside script like user event scripts, but requires making the suitelet externally available, which is extremely favorable datawise
if you are trying to send an email with the pdf, then you should be using whatever logic is in the suitelet in the user event instead, a Custom Module will allow you to share logic between a suitelet and a user event
💯 1