This topic contains 9 replies, has 0 voices, and was last updated by dmeng 7 years, 8 months ago.

  • Author
    Posts
  • #1190

    karenn

    Hi all,

    We have a BeforeLoad User Event script for the Credit Memo form that works fine when creating a Credit Memo. We just had a request to reformat the printed version of the credit memo and we are trying to customize an Advanced PDF/HTML template. We click on the standard template to customize it and every time we get an error:

    org.mozilla.javascript.EcmaError: TypeError: Cannot find function getAllParameters in object http.ServerRequest. (/SuiteScripts/PE Scripts 2.0/pe2_ue_creditmemo.js#27)

    First, not sure why it is running the script when we are trying to create a custom template.

    The line it is hanging up on is when we get a custom parameter we have passed to the form when creating a Credit Memo from a Case. Like I said, the script works just fine when created a Credit Memo either from a Case or just creating a new one independent of a case

    Here is the code. We do not even try to use the getAllParameters function in our code.

    /**

    * @NApiVersion 2.x

    * @NScriptType UserEventScript

    * @NModuleScope SameAccount

    */

    define([‘N/record’, ‘N/url’, ‘N/runtime’],

    function(record, url, runtime) {

    function beforeLoad(scriptContext) {

    if (runtime.getCurrentUser().name == ‘WebService NSPOS’) { return; }

    request = scriptContext.request;

    var recid = request.parameters.caseid;

    This last line is where it dies every time.

    I have tried various things without success. Any ideas?

    Thanks,

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

  • #1191

    starlingMark

    Hi Karen,

    Can you post the full content of your script file? I tried copying and pasting your text here exactly and intentionally introduced an error on the line “var recid = request.parameters.caseid;” and the error said it was on line 15. However, the text you posted suggests that the error is on line 27.

  • #1192

    karenn

    Here is the entire file. Thanks

    * @NApiVersion 2.x

    * @NScriptType UserEventScript

    * @NModuleScope SameAccount

    */

    define([‘N/record’, ‘N/url’, ‘N/runtime’],

    function(record, url, runtime) {

    /**

    * Function definition to be triggered before record is loaded.

    *

    * @param {Object} scriptContext

    * @param {Record} scriptContext.newRecord – New record

    * @param {string} scriptContext.type – Trigger type

    * @param {Form} scriptContext.form – Current form

    * @Since 2015.2

    */

    function beforeLoad(scriptContext) {

    if (runtime.getCurrentUser().name == ‘WebService NSPOS’) { return; }

    if (scriptContext.type == ‘create’ && scriptContext.form.title == ‘Credit Memo’)

    {

    request = scriptContext.request;

    var recid = request.parameters.caseid;

    if (recid != null)

    {

    //Creating from Case

    caseRec = record.load({

    type: record.Type.SUPPORT_CASE,

    id: recid

    });

    var customer = caseRec.getValue({fieldId: ‘company’});

    var casedate = caseRec.getValue({fieldId: ‘startdate’});

    //log.debug({title: ‘Customer’, details: customer});

    //var curRec = currentRecord.get();

    curRec = scriptContext.newRecord;

    curRec.setValue({

    fieldId: ‘entity’,

    value: customer

    });

    curRec.setValue({

    fieldId: ‘saleseffectivedate’,

    value: casedate

    });

    var caseURL = url.resolveRecord({

    recordType: record.Type.SUPPORT_CASE,

    recordId: recid,

    isEditMode: false,

    params: ”

    });

    curRec.setValue({

    fieldId: ‘custbody_pe_createdfromcase’,

    value: caseURL

    });

    var casenum = caseRec.getValue(‘casenumber’);

    var urlDisplayText = casenum;

    scriptContext.form.getField(‘custbody_pe_createdfr omcase’).linkText = urlDisplayText; //this sets the link text for the case’)

    }

    }

    }

    /**

    * Function definition to be triggered before record is loaded.

    *

    * @param {Object} scriptContext

    * @param {Record} scriptContext.newRecord – New record

    * @param {Record} scriptContext.oldRecord – Old record

    * @param {string} scriptContext.type – Trigger type

    * @Since 2015.2

    */

    function beforeSubmit(scriptContext) {

    }

    /**

    * Function definition to be triggered before record is loaded.

    *

    * @param {Object} scriptContext

    * @param {Record} scriptContext.newRecord – New record

    * @param {Record} scriptContext.oldRecord – Old record

    * @param {string} scriptContext.type – Trigger type

    * @Since 2015.2

    */

    function afterSubmit(scriptContext) {

    }

    return {

    beforeLoad: beforeLoad

    //beforeSubmit: beforeSubmit,

    //afterSubmit: afterSubmit

    };

    });

  • #1193

    starlingMark

    Karen,

    I tried running your code in our account. I did get it successfully run, but I also found where your issue is coming from.

    There is an internal script referenced when you call request.parameters. The file seems to be the N/suiteletContext module. Here is where I think you are hitting the error, on line 54:

    Code:
    44 /**
    45 * Server request parameters.
    46 * @name ServerRequest#parameters
    47 * @type Object
    48 * @readonly
    49 * @throws {error.SuiteScriptError} READ_ONLY_PROPERTY when setting the property is attempted
    50 */
    51 Object.defineProperty(this, ‘parameters’, {
    52 get: function ()
    53 {
    54 return delegate.getAllParameters();
    55 },
    I believe that when you attempt to modify an advanced template the system loads a “dummy” record for validation of fields. In this instance, it is hitting your beforeLoad script and bombing because there is no http request object.

    chanarbon Can you corroborate this? Or debunk it, whichever is appropriate

  • #1194

    karenn

    Well this is very annoying. Makes it impossible to create a template. Not good

  • #1195

    starlingMark

    You could add a line after 24 something to the tune of:

    Code:
    if (!request) {
    return;
    }

  • #1196

    karenn

    Nope. Still get error

  • #1197

    starlingMark

    One last thought – put line 25 in a try/catch block.

  • #1198

    karenn

    Yeah that would work but annoying. Oh well. 2.0 is what it is. Thanks!

  • #1199

    dmeng

    Originally posted by karenn

    View Post

    First, not sure why it is running the script when we are trying to create a custom template.

    The help docs explain the reason we run before load scripts during template customization in this page under the important note section: https://system.netsuite.com/app/help…ehead_N2863734.

    If you can’t access the link, here is what the note says: Important: Records are used to populate some values in the template. To open an advanced template for editing, NetSuite runs all before load scripts to get updates on the records and it triggers all Before Record Load Actions in workflows before it loads the template in the editor. If any before load scripts or workflow actions fail, an error message appears and you cannot edit the template until the script or workflow issues are resolved.

    FYI, I am a test engineer on the SuiteScript team and I will be looking into this issue.

You must be logged in to reply to this topic.