Skip to main content

Turning Saved Search Logic Into Insight: A Lesson in NetSuite Date Math

 Sometimes it's the smallest slice of a project that demands the most ingenuity. What seemed like a simple enhancement to a Saved Search ended up stretching my understanding of NetSuite’s formula logic—and my patience.

🔍 The Objective

I needed to compare two types of project actions occurring within a 30-day window. Here’s the twist: Project Actions are a custom child record of a NetSuite Project (Job), and they’re not stored in a way that makes direct comparison easy. So, I had to retrieve them through a Project Search, pulling in individual Action records via joins—first hurdle cleared.

📅 Date Math, NetSuite Style

Next came the math. I needed to calculate whether one action happened within 30 days of another, but NetSuite doesn’t make date arithmetic feel intuitive.

My first instinct was to use TO_NUMBER() to convert the dates into values I could compute on. Spoiler: it didn’t work. So I tried a workaround—subtracting a fixed reference date (TO_DATE('01/01/2000', 'MM/DD/YYYY')) from the actual date field. That gave me a usable numeric value.

From there, I added 30 to one date-derived value and compared it to the other. This let me flag records that didn't fall within the expected time window between the scheduled end and the response date.

♻️ Matching Actions with Summary Logic

To tie it all together, I built a Summary Saved Search. I gave one action type a positive value, and the other a negative value. If their sum wasn’t zero, I knew they didn’t properly match—exactly what I needed to surface.

Here’s the anonymized formula:

CASE WHEN {joined_project.action_type.id} = 386 AND {joined_project.related_revision_action} IS NULL THEN NVL({joined_project.scheduled_end_date}, TO_DATE('01/01/1900', 'MM/DD/YYYY')) - TO_DATE('01/01/2000', 'MM/DD/YYYY') + 30 WHEN {joined_project.action_type.id} = 388 AND {joined_project.related_revision_action} IS NULL THEN -1 * (NVL({joined_project.response_date}, TO_DATE('01/01/2999', 'MM/DD/YYYY')) - TO_DATE('01/01/2000', 'MM/DD/YYYY')) ELSE 0 END


✏️ What I Learned

  • NetSuite date math demands creativity and patience.
  • Static reference dates can be a clever workaround to enable meaningful comparisons.
  • Summary logic lets you track imbalance elegantly when child records don’t align as expected.

It wasn’t the biggest task of the week—but it packed more problem-solving into a few lines of SQL than I anticipated. The takeaway: complexity isn’t in the size, it’s in the detail.  And I may learn a better way in the future, but I found A way.

Comments

Popular posts from this blog

Logo Design

I started working on some Freelancer.com Contests.  It's been good to push me to create some work within a somewhat restricted space.  Also helping me keep the creative juices flowing.  This is a design I did for Philippe Diamonds.  It was rejected.  I like it though, so I thought I would share. I have worked on a bunch of others, either they aren't done yet, or I don't fully endorse the design.

Delta Cubes - The Dark Side of The Greendale

I'm a huge fan of Community ( @nbccommunity )  And I am also a huge fan of Pink Floyd.  So I decided to do a little mash-up after watching the last episode Season 04 Episode 07 - "Economics of Marine Biology"  And since I haven't posted in awhile, I thought I would Share.

Mitt Romney Poster

Romney 2012 Believe in America Trying to again stay productive, and get more work out there and into my portfolio.  Did a quick Poster of Mitt Romney. I am not necessarily Endorsing him, but  wanted to do someone who was relevant to the times.