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

  • Author
    Posts
  • #18441

    karenn

    Hello all,

    We have a suitelet that is working fine. In the form created by the suitelet are some links with parameters to another suitelet along with some other data and two fields with a start and end date for the search that is used for the data. So far so good.

    Now on this 2nd Suitelet form that is displayed when clicking on one of the links is a button to return to the first suitelet. We need this to allow the user to go back and basically reload the first suitelet page because using the browser back button pops up a message about confirming form resubmission. We want to avoid that. So we have a button that calls a function in a client script which does a window.location.href. This works great but this would just reload the 1st suitelet using the original date values and not the last date values that were being used to gather the displayed data.

    The problem is, how to get the start and end dates that were passed to the 2nd suitelet into the client script so they can be added to the href value so the original suitelet can be reloaded with the data for that date range again.

    I feel like I am missing something obvious here but have been staring at this too long to see it.

    Thanks,

    Karen
    This is a cached copy. Click here to see the original post.

  • #18442

    david.smith

    Hi Karen. There are a few ways you could handle this. From your note I’m guessing that the links don’t open a new window but rather replace the 1st suitelet page with the next.

    On my suitelets I always distinguish the GET method from the POST methods. Usually I will create a single page application that allows for the initial page to post back to itself to adjust/change data. Doesn’t sound quite like that’s what you’re doing here.

    I would create a set of parameters that have your dates. Something like &sd=2017-06-01&ed=2017-06-01 passed to the second suitelet it can just give them back to the first so you can then know to use those when building the page.

  • #18443

    karenn

    HI David

    Yeah, that is what I am trying to do. I am passing the parameters to the second suitelet just like you have said. I can access these in the 2nd suitelet no problem but how do I add these into the url created with the “Back” button is clicked on the form since the button onclick function has to be in a client script and does not know about these parameters from everything I have seen.

    Thanks,

    Karen

  • #18444

    david.smith

    Ah, I see.

    Don’t use the standard “back” button. Create a new one that calls a client script function that then sends them back to the first suitelet. It’s a little extra work but well worth the added control you have.

  • #18445

    karenn

    Right sorry. Too many distractions here. I am creating my own button

    Here is the basics what I have.

    2nd Suitelet:

    define([‘N/ui/serverWidget’, ‘N/record’, ‘N/search’, ‘N/file’, ‘N/format’],

    function(ui, record, search, file, format) {

    /**

    * Definition of the Suitelet script trigger point.

    *

    * @param {Object} context

    * @param {ServerRequest} context.request – Encapsulation of the incoming request

    * @param {ServerResponse} context.response – Encapsulation of the Suitelet response

    * @Since 2015.2

    */

    function onRequest(context) {

    var request = context.request;

    //log.debug({details: request.parameters.sd});

    var response = context.response;

    var styleHeader = ‘background-color: #d0e6b6;’;

    var styleEvenRow = ‘background-color: #F0F0F0;’;

    var styleOddRow = ‘background-color: White;’;

    var styleTotalRow = ‘background-color: #6490ED;’;

    var sd = request.parameters.sd;

    var ed = request.parameters.ed;

    var form = ui.createForm({

    title: “Packer Incentive – Cases”

    });

    var field = form.addButton({

    id: ‘custpage_btn_back’,

    label: ‘Back’,

    functionName: ‘goBackPackerIncentive’

    });

    form.clientScriptFileId = 573442;

    response.writePage(form);

    }

    return {

    onRequest: onRequest

    };

    });

    client script id 573442 that goes back to the first suitelet when custom back button is clicked.

    /**

    * @NApiVersion 2.x

    * @NScriptType ClientScript

    * @NModuleScope SameAccount

    */

    define([],

    function() {

    /**

    * Function to be executed after page is initialized.

    *

    * @param {Object} scriptContext

    * @param {Record} scriptContext.currentRecord – Current form record

    * @param {string} scriptContext.mode – The mode in which the record is being accessed (create, copy, or edit)

    *

    * @since 2015.2

    */

    function pageInit(scriptContext) {

    }

    function goBackPackerIncentive()

    {

    window.location.href = ‘/app/site/hosting/scriptlet.nl?script=369&deploy=1’;

    }

    return {

    pageInit: pageInit,

    goBackPackerIncentive: goBackPackerIncentive

    };

    });

    So in the goBackPackerIncentive, how to I get the sd and ed values to pass back?

    Thanks!

  • #18446

    david.smith

    lazy man’s way…. add and inlinehtml field to the second suitelet and put something like this on the page

    Code:
    ‘var sd=”‘+sd+'”; var ed=”‘+ed+'”;’
    then in your client scirpt you can add to the href

    Code:
    ….&deploy=1&sd=’+sd+’&ed=’+ed
    something like that anyway…

  • #18447

    karenn

    Brilliant! As always, very helpful. Thanks!

You must be logged in to reply to this topic.