Friday, October 5, 2018

Use Array for setLineItemValues in a Suitelet Custom Sublist

1.Upload the Script below as a Suitelet    Navigate to Customization > Scripting > Scripts > New > Suitelet     Name : Enter Name    Function : createForm    File : Select the created javascript file   Click Save & Deploy 2.On the Script Deployment     Name : Enter Name   Assign the Audience    Status : Testing   Click Save 3. Navigate back to the deployment then take note of the URL *** Please see the line comments for further explanation   

function createForm(request, response){ if (request.getMethod() == 'GET') { //create the Array object        var itemArray = new Array(); /* * assign the values to the array these are arrays of name/value pairs * the first value is the field name on the sublist * the second value is the actual value of the field * for select field internal id's of the field will be used * change the id's with the one existing in the account being used * since these are only examples */ itemArray[0] = {'item':15,'location':1, 'rate':'150.00'}; itemArray[1] = {'item':5,'location':3, 'rate':'200.00'}; itemArray[2] = {'item':14,'location':4, 'rate':'250.00'}; //create the Form where the Sublist will be attached var form = nlapiCreateForm('Sample Item Sublist', true);         //add the Sublist onto the Form var itemList = form.addSubList('custpage_send_to_flex', 'list', 'Items'); //create the Fields for the Sublist var itemField = itemList.addField('item','select', 'Item', 'item');  var locationField = itemList.addField('location', 'select', 'Location', 'location'); var rateField = itemList.addField('rate', 'currency', 'Rate', null); //assign the array values on the Sublist using setLineItemValues itemList.setLineItemValues(itemArray); //write the form on the reponse of the Suitelet response.writePage( form ); }
}


For an example using saved search in setLineItemValues please see the help guide for the sample script:  Adding Sublists with SuiteScript

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations. NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto. NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

2 comments:

  1. I agree with a lot of the points you made in this article. If you are looking for the Array Interview Questions, then visit TutorialCup. I love your content, they are very nice and very useful to us and this text is worth everyone’s attention.

    ReplyDelete
  2. Thanks for shared that blog with us. If anyone here searching Linkedlist Interview Questions then visit TutorialCup.

    ReplyDelete