This topic contains 7 replies, has 0 voices, and was last updated by elie 8 years, 1 month ago.

  • Author
    Posts
  • #1650

    elie

    Is there any way to use the 2.0 currentRecord module to access the fields on a Suitelet and use fieldChanged events (and others, like postSourcing, etc) to modify fields on the page?

    I’ve seen examples of buttons added with clientScriptModulePath or File, but no sample script deployments. I wouldn’t know which record to deploy to, being that the Suitelet is a standalone form… Is there any way to accomplish this?

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

  • #1651

    david.smith

    Yes. Extending the example a little from yesterday. As long as your suitelet outputs the NS form.

    Suitelet

    Code:
    //form.clientScriptFileId = 1077203;
    form.clientScriptModulePath = “SuiteScripts/SWK/form_client.js”;
    var custSelect = form.addField({
    id: ‘custpage_client’,
    type: ui.FieldType.SELECT,
    label: ‘Client’,
    container: ‘filtergroup’
    });

    Client

    Code:
    /**
    * @NApiVersion 2.x
    * @NScriptType ClientScript
    */
    define([‘N/ui/message’, ‘N/ui/dialog’,’N/url’],
    function(message, dialog, url) {
    function pageInit(context) {
    console.log(‘page init’);
    }
    function fieldChanged(context){
    console.log(context);
    if(context.fieldId==”custpage_client”){
    var name = context.currentRecord.getText({fieldId:”custpage_client”});
    var id = context.currentRecord.getValue({fieldId:”custpage_client”});
    console.log(id,name);
    }
    }
    return {
    pageInit: pageInit,
    fieldChanged: fieldChanged
    };
    โ€‹ });

  • #1652

    david.smith

    Originally posted by elie

    View Post

    Is there any way to use the 2.0 currentRecord module to access the fields on a Suitelet and use fieldChanged events (and others, like postSourcing, etc) to modify fields on the page?

    I’ve seen examples of buttons added with clientScriptModulePath or File, but no sample script deployments. I wouldn’t know which record to deploy to, being that the Suitelet is a standalone form… Is there any way to accomplish this?

    Thanks

    Sorry, forgot to answer this directly. Your client script in this case does not need a script and deployment record. It can be a stand alone file in the FC. You just need to add the path to the define([‘/SuiteScripts/somepath/somefile’],….)

  • #1653

    elie

    I had tried something like that, but it seems like Netsuite doesn’t like it for some reason. I now noticed after looking at it that although nothing was firing (no console.log), there was something different about the page. When I loaded the Suitelet without the client script referenced, I was able to select the options from the dropdown. After assigning the client script, the Ui behaves funny. Not sure what that would be…

    I pretty much have similar scripts to what you posted, though…

  • #1654

    elie

    …and just like that, now it works. I had used the Eclipse to build the template for me to use and that seems to have caused the scripts to fail. Must have been because I had all of the methods / script execution types declared but not really defined (none of them had any body, so many return trues were missing).

    Thanks for your assistance David (you are the bomb – I’ve seen you posting all over the place with 2.0 help)!

  • #1655

    david.smith

    Anytime. I’m still learning too. Glad to share.

  • #1656

    elie

    So, I am not understanding something here. In 2.0 there is no equivalent to nlapiInsertOptions or nlapiRemoveOptions – as is evident in the map from 1.0 to 2.0.

    How would I accomplish something like this in 2.0 on the client?

    Code:
    //Add the department/proj field
    var deptProjField = itemSublist.addField({
    id: ‘dept’,
    type: ui.FieldType.SELECT,
    label: ‘Dept/Project’
    });

    deptProjField.addSelectOption({
    value: ‘ ‘,
    text: ‘ ‘
    });

    var deptSearch = search.load({
    id: ‘customsearch_pri_trx_app_departments’
    });

    log.debug(‘Dept search filters’, deptSearch.filters);

    deptSearch.filters.push(search.createFilter({
    name: ‘subsidiary’,
    operator: search.Operator.IS,
    values: 9
    }));

    //Run the search
    var deptSearchResult = deptSearch.run().getRange({
    start: 0,
    end: 1000
    });

    for (var i = 0; i < deptSearchResult.length; i++) {
    var deptID = deptSearchResult[i].getValue({
    name: 'internalid'
    });

    var dept = deptSearchResult[i].getValue({
    name: 'name'
    });

    log.debug('Dept', deptID + ': ' + dept);

    //Populate the dropdown with the results of the search
    deptProjField.addSelectOption({
    value: deptID,
    text: dept
    });
    }

  • #1657

    elie

    FYI, there is a reference to the subsidiary in the code (values: 9). I am trying to force the user to select the sub, and then update a few fields based on that selection, including the department, as illustrated above. The code itself works in the Suitelet, but I need it to happen on the client side…

    Thanks!

You must be logged in to reply to this topic.