Good Morning, I a created a button that on a sales...
# suitescript
k
Good Morning, I a created a button that on a sales order. That button should open up a pdf template suitelet. But I am getting an error saying page not found. Do you have any links or source code I can work with to get the job done
c
Not really enough information? Why is the page not found? Are you generating the URL correctly? Have you checked the URL?
k
const beforeLoad = (scriptContext) => {
try{
const recCurrent = scriptContext.newRecord;
const objForm = scriptContext.form;
const stStatus = recCurrent.getValue({
fieldId: 'status'
})
const stSuiteLinkParam = runtime.getCurrentScript().getParameter({
name: 'customscript_suiteletpdflink'
})
const suiteletURL = '\"' +  stSuiteLinkParam + '\"';
if(stStatus === 'Pending Fulfillment'|| stStatus === 'Partially Fulfilled'){
objForm.addButton({
id: 'custpage_printbackorderitems',
label: 'Print BPI',
functionName: 'window.open(' + suiteletURL + ')'
})
}
}catch(error){
log.error({
title: 'Add Suitelet Button',
details: error.message
})
}
}
This is the code I am using to generate the url. I have create a suitelet file that had the ootb code in it.
Copy code
const onRequest = (scriptContext) => {
    var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n" +
        "<pdf lang=\"ru-RU\" xml:lang=\"ru-RU\">\n" +
        "<head>\n" +
        "<link name=\"russianfont\" type=\"font\" subtype=\"opentype\" " +
        "src=\"NetSuiteFonts/verdana.ttf\" " +
        "src-bold=\"NetSuiteFonts/verdanab.ttf\" " +
        "src-italic=\"NetSuiteFonts/verdanai.ttf\" " +
        "src-bolditalic=\"NetSuiteFonts/verdanabi.ttf\" " +
        "bytes=\"2\"/>\n" +
        "</head>\n" +
        "<body font-family=\"russianfont\" font-size=\"18\">\nРусский текст</body>\n" +
        "</pdf>";
    context.response.renderPdf(xml);
}

return {onRequest}
b
the most obvious point of failure is the code related to
stSuiteLinkParam
make sure that the variable contains the value you expect
r
Use
url.resolveScript
, not a parameter.
I would also use a client side button handler in
form.addButton