This topic contains 6 replies, has 0 voices, and was last updated by chanarbon 8 years, 1 month ago.
-
AuthorPosts
-
October 18, 2016 at 1:47 pm #6061
lfernandesIs it possible to have a suiteflow that displays a button then if that button is clicked it calls a server side script?
For example, I have a few custom pdfs that are created via scripts and like to have a button to trigger their creation.
-“Print Custom PDF” button
-Button is clicked – Calls server side script that creates the PDF
-PDF opens
This is a cached copy. Click here to see the original post. -
October 18, 2016 at 2:06 pm #6062
david.smithYou would have to call a client script that called the server suitelet. Your suitelet can have the response be the PDF.
-
October 18, 2016 at 5:59 pm #6063
michoelI typically do this using a User Event Script to add the button and a Suitelet to generate the PDF.
Code:
/**
* Add ‘Print Item Labels’ button to Item Page
*
* Script ID: customscript_mos_itemlabels_ue
* Script Type: User Event
* Deployed to: Inventory Item
*
*/function beforeload(type, form) {
if (type == ‘view’) {
var script = “window.open(nlapiResolveURL(‘SUITELET’, ‘customscript_mos_itemlabels_sl’, ‘customdeploy_mos_itemlabels_sl’) + ‘&custom_id=’ + nlapiGetRecordId());”;
form.addButton(‘custpage_printitemlabel’,’Print Item Label’, script);}
}/**
* Suitelet to print Item Label
*
* Script ID: customscript_mos_itemlabels_sl
* Script Type: Suitelet
*
*/function suitelet(request, response) {
try {var id = request.getParameter(‘custom_id’);
if(! id) {
response.write(‘custom_id parameter missing’);
}var record = nlapiLoadRecord(‘inventoryitem’, id);
var renderer = nlapiCreateTemplateRenderer();
var template = nlapiLoadFile(‘SuiteScripts/MOS Advanced PDF Forms/Item Label.xml’);
renderer.setTemplate(template.getValue());
renderer.addRecord(‘record’, record);
var xml = renderer.renderToString();
var pdf = nlapiXMLToPDF(xml);
response.setContentType(‘PDF’, ‘itemlabel.pdf’, ‘inline’);
response.write(pdf.getValue());} catch(err) {
response.write(err + ‘ (line number: ‘ + err.lineno + ‘)’);
return;
}
} -
October 19, 2016 at 1:43 am #6064
chanarbonPitching in some information and to sum up the process:
Can a Suiteflow created button call the server-side script that will create the PDF? SuiteFlow buttons are rather good for transitioning and not on this scenarios. And it would be a better thing to consider a user event script deployed on Before Load to perform the task of adding the button.
The Process:
1. User Event on Before Load creates the button and the button action would either be of two option:
Option A: Similar to the process that michoel provided which is an embedded function
Option B: The the function placed on a client script
2. When the button is clicked, perform a call to the Suitelet where you also have two options on displaying it
Option A: Display it on another window using window.open
Option B: Displaying the PDF using a lightbox (which would cause you some time to render)
3. The Suitelet should return a PDF file. If you are using the case provided by michoel, it will show the PDF with you pdf plugin on your browser. Else you will get it downloaded (whic you can open with an PDF application e.g. Adobe Reader).
-
October 19, 2016 at 8:15 am #6065
lfernandesThanks everyone. I currently have 6 custom pdfs set up as you all have described. I was hoping to simplify the process a bit… perhaps in the future we can embed suitescript in workflows
-
October 19, 2016 at 9:06 am #6066
erictgrubaughYou can embed SuiteScript in Workflows via Workflow Action scripts, but I don’t believe those help you in this particular use case of handling button clicks.
-
October 20, 2016 at 12:16 am #6067
chanarbonIn line with Eric’s note above, yes you can embed SuiteScript together with WF using workflow action script although the available triggers for WFA Scripts wouldn’t match to the triggers required for Lorie-lyn’s cases. More of less, the course of action to implement the solution would be michoel’s proposition.
-
AuthorPosts
You must be logged in to reply to this topic.