Land Cook
Land Cook

Reputation: 1

How to loop through all line items of a sales order and get the earliest term start date

We are building out the ARM module of Netsuite and our director of Accounting would like the Contract Start date on the header level to be populated with the earliest Term Start date from the line items on the sales order.

I'm just starting this project and am new to Suite Script. I'm hoping to get pointed in the right direction and work f rom there.

Upvotes: 0

Views: 1909

Answers (2)

Victor Chern
Victor Chern

Reputation: 141

You can also do this in the UI without SuiteScript.

  1. Create a saved search with results as Term Start Date with a summary of Minimum.
  2. Add any criteria that you may need (such as Term Start Date is not empty)
  3. Add a filter of Internal Id.
  4. Create the custom field, and under Validation and Defaulting select the previously created saved search. Make sure that stored value is checked off for the custom field!

Look into the article "Creating Custom Fields with Values Derived from Summary Search Results" in the help center for more information!

Upvotes: 0

Avi
Avi

Reputation: 2069

To filter earliest date from lines, you first need to fetch all the dates which can be done using record.getSublistValue which requires a set of parameters which you can find here. Once you have filtered out the date, you can set it on body field using record.setValue and you can find its documentation here.

To get the record, it depends on which script-type you are working on, like if you are sripting in User-Event, you will receive newRecord in its script parameter. Whereas if you are working on some scheduled/map-reduce script, you might have to load the record using record.load from N/record module.

Upvotes: 1

Related Questions