Skip to content


SuiteScript Tip #1. nlapiGetCurrentLineItemValue() vs nlapiGetLineItemValue()

Stumbled upon Scripting tip-25:Difference between nlapiGetCurrentLineItemValue vs nlapiGetLineItemValue earlier today— Apparently I am not alone when it comes to understanding the oddities of SuiteScript. I have a couple small insights I came across and decided it was worth posting my own version of the subject.

When dealing with sublists for a NetSuite record, there are two ways of accessing line items: [1] nlapiGetCurrentLineItem___(type, field) and [2] nlapiGetLineItem___(type, field, lineNum). These two functions perform the same in most contexts (when available). The crucial difference between these two APIs is in Client Scripts. Because of the order of function calls in how NetSuite handles Client events, e.g. fieldChanged, Recalc, lineInsert, etc., the two sets of APIs can refer to different sets of values.

For fieldChanged, or Recalc scripts, the nlapiGetCurrentLineItem___() functions will refer to the last values before the event occurred, while the nlapiGetLineItem___() will refer to the new current clean model of the data.

For example, if you are working on a SalesOrder and change the quantity 123 to 456, you will have the following in the fieldChanged() function:

> nlapiGetCurrentLineItemValue('item', 'quantity' ) = 123

> nlapiGetLineItemValue( 'item', 'quantity', line ) = 456

This oddity in behavior will be applied both in fieldChanged and Recalc functions. While this seems a bit confusing, there is a parallel that can be seen while using the UI. When using the UI, a fieldChanged event will be called after any field is changed, including columns in a line item, e.g. changing the quantity for a line item. The line is not committed until the Add/Edit button is clicked. This event corresponds to the validateLine event.

Similarly, when you remove an item, the nlapiGetCurrentLineItem___() functions will point to the previous (and now removed) line item. Assume we start with 3 line items, and then proceed to remove the first item. In the Recalc function call when the item is removed, the lines will report the correct new number:

> var totalLines = nlapiGetLineItemCount('item') = 2;

while calls to nlapiGetCurrentLineItem___() will return the old removed lined:
> nlapiGetCurrentLineItemValue('item', 'item' ) = Item#1
> nlapiGetCurrentLineItemValue('item', 'quantity' ) = 123

and calls to nlapiGetLineItem___() will return the values for line #2.

> nlapiGetLineItemValue('item', 'item', 1 ) = Item#2
> nlapiGetLineItemValue('item', 'quantity', 1 ) = 456

Odd but true..

In the code I have been working on, a particular line item can have a dependent line item following it. So when the item is removed, the Recalc handler has the following code:

1
2
3
4
5
6
7
8
function recalc(type, name ) {
  if (type == 'item' && name == 'remove') {
    var lineNum = parseInt (nlapiGetCurrentLineItemIndex('item')); //same line as current
    if (nlapiGetCurrentLineItemValue('item', 'item') == '1000') { //check value of removed item
      nlapiRemoveLineItem('item', lineNum ); //removes line following line of what was just removed
    }
  }
}

It makes sense when you understand the NetSuite model, but it still is confusing at times without the comments.

Posted in NetSuite.

Porting RandomNumber Project from Cocoa to iPhone

As discussed in my earlier post, I have been working on porting my simple RandomNumber Cocoa application to the iPhone. I encountered a mysterious EXC_BAD_ACCESS error because an object I instantiated in Interface Builder is being dealloc-ed immediately after it is created. I posted this discussion over at forums.macrumors.com, and was able to find an answer by PhoneyDeveloper that explained why I encountered the EXC_BAD_ACCESS error in the iPhone Application but not the Cocoa Application.

There are differences in how outlets are managed between MacOS X cocoa and iPhone OS UIKit. On UIKit you need to retain all top level objects from your nib. This is almost always done by having retaining properties for your IBOutlets.

And the final insight to my dilemma was:

If you are creating the Engine object in IB then that object must be an IBOutlet also. Typically that would be done in the view controller, which is the File’s Owner.

With that solved, Figure 1 shows the final product for RandomNumberIPhone.

Figure 1: RandomNumberIPhone Finished Project

Continued…

Posted in iPhone, Mac.

iPhone UIDatePicker Tutorial

After completing my RandomNumber Cocoa application, I decided to try to port the project over to the iPhone. Unfortunately, I encountered a mysterious EXC_BAD_ACCESS error because an object I instantiated in Interface Builder is being dealloc-ed immediately after it is created. I posted this discussion over at forums.macrumors.com, and was able to find an answer by PhoneyDeveloper that explained why I encountered the EXC_BAD_ACCESS error in the iPhone Application but not the Cocoa Application.

There are differences in how outlets are managed between MacOS X cocoa and iPhone OS UIKit. On UIKit you need to retain all top level objects from your nib. This is almost always done by having retaining properties for your IBOutlets.

I am waiting to hear back if there is a property I need to add to get my Interface Builder-instantiated class to work correctly. Once I am able to remedy the issue, I will post a tutorial for my RandomNumber iPhone application. As an aside, an alternative that works is to do the linking through the ViewController (which is the standard way if you instantiate the classes through Xcode instead of Interface Builder, since, as the owner of the View, it will not be dealloc-ed.

In the meantime, I have created a short tutorial on how to use the UIDatePicker class. While my tutorial is based on this tutorial,  my goal is to understand how to use these different UI components, and understand the process flow between Xcode and Interface Builder. The final  UIDatePicker product looks like:

Figure 1: Final DatePicker1 Project

Continued…

Posted in iPhone. Tagged with .

Introduction to XCode and Interface Builder

I have been searching for a good place to start, but have found mainly overly technical specifications, overviews and reference material. One good article I have found is Getting Started with Cocoa Programming. The article provides a sample project used in their book Cocoa Programming for Mac OS X, 2nd Edition. While my ultimate goal is to learn iPhone development, I found this guide to be an excellent start to learning Xcode and Interface builder. While the guide is very thorough, I am providing an updated version based on my experience in Xcode and Interface Builder 3.2.2.

The final project is shown in Figure 1. The program has a single window with two buttons and a text field.

Figure 1: RandomNumber Completed Project


Continued…

Posted in Mac. Tagged with , , .

iPhone and iPad Development

Its mid-2010 and as of this past Tuesday, Apple has just overtaken Microsoft as the most valuable technology company in terms of market capitalization and value. This represents a profound paradigm shift in the technology field where once bigger and faster is better to one where design, functionality, and simplicity is paramount. In other words, technology is now not about just raw computational power, but rather how we can integrate technology to simplify our lives and improve the quality of our lives and social relationships.

With all that being said, anyone who has owned or seen an iPod, iPhone, or iPad, or even just used a Mac, will know that Apple has been reorganizing and reinventing the way we interface with computers and smart devices. As a solid Mac user, I am now befuddled by the difficulty and complexity of performing simple tasks on my Mac, iPhone, and iPad, on my Windows PC and Linux machines. In reality its not that Windows and Linux have gotten more complex, its that (1) the number and diversity of tasks I would like to do have increased and (2) the time and energy I can devote for customizing, tweaking, and hacking is a lot less these days. My paradigm now a days is to use technology as a tool to facilitate my daily life.

With the spring semester over, I have a lot more free time, and have decided to try writing software for the Mac, iPhone, and iPad. I will be blogging the path I am taking and what I have accomplished online. Stay tuned for more.

Posted in iPhone, Mac.

Sony VGN-FS830 Laptop Memory Woes

While I’ve moved away from my computer repair days, I still occasionally take a “my computer has a problem” request. So this latest one was regarding a friend’s Sony VGN-FS830 (PCG-&G2L Series) with a 1.73G Pentium M Processor and 512GB Memory running Windows XP SP3. After scanning Add/Remove Programs and running a virus scan, I concluded the system was pretty clean with minimal bloatware. So I then proceeded to Start up Task Manager and see how much memory the system was using during normal operations. After starting up some medical software, Internet Explorer, and Firefox, the system was running 600MB+ of virtual memory and 460MB+ of the physical 512MB (includes resident programs too). I consider these levels quite high.. So logically my next step was to determine the memory type and proceed to get additional memory.

When I opened up the memory compartment, I noticed there was quite a bit of dust and other particles lodged in the compartment and on the memory module. This has never really been a problem before, so I did my best to remove the loose dust and particles and continued on my way. After determining the system uses DDR2 SoDimms (2 slots total, only 1 used), I proceeded to reinstall the memory and boot the system up.

To my surprise the system would not post. The power light and hard drive light would come on. I would even hear the hard drive try to power on. However, no post, and not Windows XP start up. This was really quite surprising and alarming considering this was being done pro-bono. I took the memory out a couple times, dusting it each time before reinserting, with no avail. I took the battery out and then tried my tricks again… Again with no avail. My next course of action was to try booting the system without memory and then with the memory in the second slot. Both of these options yielded similar results. This gesture of friendship was looking to turn ugly.

So I headed to the store to buy a 1GB SODimm and a can of air (to help clean the crud). On my way to the store, I did a quick google search for Sony laptops not posting, and found some rather discouraging and also bizare results (e.g. use shrink wrap to put pressure on the memory). So in the back of my mind, I knew either the memory or system was now defunct… and hoped I can pull something together so I didn’t have to tell my friend I toasted his laptop. I purchased these items (and of course checked the return policy). When I got home, did a quick dusting of the compartment and installed the original SODimm back in Slot 1 (making sure the SODimm was seated completely in and locked in place.. And to my surprise and relief, the machine actually posted! I then went ahead and installed the second SODimm.. and the system still booted and is now reporting 1.5GB of memory. So mission accomplished!

I’m still not quite sure what did the trick with the memory. Either the SODimm wasn’t properly seated, and/or perhaps the machine needed some time to reset (machine was unplugged with no battery while I went to the store… approx 30min). Definitely a case for the unsolved mysteries file (No.. I don’t really need to know why it all happened..)

Posted in Ramblings.

2010 New Year’s Resolutions

This could just be a sign of old age, but the years seem to come and go in the blink of an eye.. It’s now 2010.. Two more years until the “end of the world” in 2012 as foretold by translations of the Mayan calendar.. Whether the world really does end or not (as it’s highly probable) it’s a new year with (re-)new hopes and aspirations. The strongest of these are captured in our new years resolutions. I haven’t had the opportunity to gooogle everybody’s top 10 or fav five, but I suspect it would be

  1. Loose weight / Get in shape
  2. Be a better (personality/actions) person
  3. Start a new hobby or get back into an old one
  4. Quit smoking or some other addictive habit
  5. Live a healthier lifestyle

Instrumenting such dramatic change can be often time nothing more than 3 weeks of attempting and 49 more of the status quo. Of course its better to try and fail then never try at all..

This year I have a couple new year’s resolutions.. Three of the smaller yet meaningful ones I have this year are (in no particular order):

  1. To read more
  2. To write more
  3. Make todo lists

I think its important to read to not only keep up with the world and current events, but also to keep our mind active and engaged. No man is an island unto himself, and being thus, we have to be aware and informed about the the world we live in, and how it has, does, may, and will affect our lives. Of course, the needs of the individual are equally important. Top on that list is the need for self-expression. I believe writing provides people a medium to collect and express their thoughts. Of course its good to get out and socialize and verbalize ourselves and our beliefs, but I think writing is a better instrument to collect and nurture our infant thoughts. The finally one on my list above is to make todo lists. I used to be an avid believer of todo lists, but somewhere down the line, this awesome management tool feel into neglect. I think todo lists helps us not only keep track of what we need to do, but also helps us budget our time, itemize and prioritize complex and in-depth tasks, as well as removes some of the mental clutter and the anxiety and stress that goes along with it.

So bottom line, I will be taking better advantage of my Amazon Prime membership, starting with A Whole New Mind: Why Right-Brainers Will Rule the Future, will be blogging more, and trying to be better organized…

Todo List

  1. Make Todo List

[amazonshowcase_822dc33d69b3a8a67fb03f792e5b8249]

Posted in Ramblings. Tagged with , .

Adjunct Teaching Position at HCC

After a long hiatus in the core technology field, I am planning my return. I applied for a position at Houston Community College (HCC) a couple weeks ago and will be finalizing the paperwork in the weeks to come. As my close friends already know, I have a love-hate relationship with technology. On the positive end of the spectrum, technology has transformed and improved our lives in innumerable ways (and is continuing everyday). On the negative end, however, technology is just a tool. It can be very mechanical and programmatic at times, and is in many ways inharmonious with the emotional, psychological, and intuitive aspects of our lives and every day needs. So for example, we can “google” most anything. But then, its our job to filter the results for relevancy, quality, and integrity.  But this is a discussion for a different day.

My current understanding is that I will be teaching a C++ class in the spring. In the long run, I hope the flexibility of the HCC system allows me to teach more cutting edge technologies, the top on my list, being to teach programming for mobile devices, such as the iPhone, Blackberry, and Android phones.

Posted in Education.

New Website Up!

Hi! My names is James Sasitorn and this is my website. I have a variety of interests and goals. My goal here is to focus on my professional goals related to technology, computer science, programming, website design, consulting work, and how to incorporate technology in every day life. Thanks for checking it out. Send me any comments or thoughts you have…

Posted in Ramblings.