This topic contains 6 replies, has 0 voices, and was last updated by chanarbon 7 years, 10 months ago.

  • Author
    Posts
  • #6061 Score: 0

    lfernandes
    • Contributions: 0
    • Level 1

    Is 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.

  • #6062 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    You would have to call a client script that called the server suitelet. Your suitelet can have the response be the PDF.

  • #6063 Score: 0

    michoel
    • Contributions: 0
    • Level 1

    I 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;
    }
    }

  • #6064 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    Pitching 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).

  • #6065 Score: 0

    lfernandes
    • Contributions: 0
    • Level 1

    Thanks 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

  • #6066 Score: 0

    erictgrubaugh
    • Contributions: 0
    • Level 1

    You 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.

  • #6067 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    In 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.

You must be logged in to reply to this topic.