Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

NetSuite – SuiteScript 2.0 – Useful Functions

Posted on August 31, 2018 By David Kittell

These first function snippets are from https://gist.github.com/W3BGUY

Set Scheduled Script Percent Complete
/**
 * @NApiVersion 2.x
 * @NScriptType ScheduledScript
 * @NModuleScope SameAccount
 *
 * According to the documentation this is a read-only field.  According to this working code and a verification from
 *    NetSuite tech support, the documentation is wrong.  Hope this helps someone out.
 *
 */
define(['N/runtime','N/record'],function(runtime,record){
  return {
    execute:function(context){
      var script=runtime.getCurrentScript();
      for(x=0;x<500;x++){
        var rec=record.create({type:'salesorder'});
        script.percentComplete=(x*100)/500;                              
      }
    }
  };
});
Search for Inventory Items and return an array of all active items
require(['N/search','N/record'],function(search,record){
  function buildItemArray(){
    var itemArray=[];
    searchItems();
    itemArray=runSearch(itemArray);
    deleteSearch();
    log.debug(itemArray);
  }
   
  function searchItems(context){
    var itemSearch=search.create({
      type:search.Type.INVENTORY_ITEM,
      title:'Inventory_Item_Search',
      id:'customsearch_inventory_item_search',
      columns:['internalid','itemid'],
      filters:['isinactive','is','F']
    });
    itemSearch.save();
  }
   
  function runSearch(itemArray){
    var mySearch=search.load({id:'customsearch_inventory_item_search'});
    mySearch.run().each(function(result){
      var item={};
      item.itemID=result.getValue({name:'itemid'});
      item.internalID=result.getValue({name:'internalid'});
      itemArray.push(item);
      return true;
    });
    return itemArray;
  }
   
  function deleteSearch(){
    search.delete({id:'customsearch_inventory_item_search'});
  }
   
  buildItemArray();
});
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code NetSuite SuiteScript 2.0

Post navigation

Previous post
Next post

Related Posts

Find Table Differences And Sync Tables

Posted on May 26, 2015October 26, 2015

Have two databases with the same table schema and need to keep both up to date? First, let us look at the differences between the two databases. The query below will show the differences between the development database table tbl_zip_code and the production database table tbl_zip_code. Ideally the differences should…

Read More

Oracle Clean Date Format

Posted on September 18, 2013October 26, 2015

Sometimes you have to pull a date from Oracle in a cleaner format, this is one way to achieve the format you want. // Convert the Oracle date 19000101 to 01-01-1900 public string OracleCleanDate(string strDate) { if (strDate.Length == 8) { string strYear, strMonth, strDay; strYear = strDate.Substring(0, 4); strMonth…

Read More

UNIX – Pi-Hole Project – Statistics

Posted on April 21, 2017June 10, 2019

If you are using Pi-Hole you may find this script useful Currently this is designed to run on the server that is running Pi-Hole but as I have more than one I want to monitor I will soon have an update for additional. First make sure you update your /var/www/html/admin/scripts/pi-hole/php/data.php…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - Get Text Encoding Type
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - IIS Remove Site
  • Javascript - Digital Clock with Style

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - Get Text Encoding Type
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - IIS Remove Site
  • Javascript - Digital Clock with Style
  • Bleaching Wool using Hydrogen Peroxide
©2025 David Kittell | WordPress Theme by SuperbThemes
David Kittell
  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support