RelativeDate Object Members in SuiteScript for Queries

The RelativeDate object in SuiteScript allows querying with defined time intervals, enhancing data filtering capabilities.

·2 min read·View Oracle Docs

The RelativeDate object in SuiteScript provides developers with the ability to use relative dates in query conditions, offering a dynamic way to filter records based on time intervals. This object, introduced in SuiteScript, supports a range of scripting needs and is essential for creating flexible and time-sensitive queries.

What is the RelativeDate Object?

A RelativeDate object allows you to represent a specific moment in time, facilitating the creation of query conditions through the use of operators such as query.Operator.AFTER, query.Operator.BEFORE, and query.Operator.WITHIN. This enhances your ability to filter data dynamically based on time.

How to Create a RelativeDate Object

To create a RelativeDate object, utilize the query.createRelativeDate(options) method. This method allows you to define various properties associated with the relative date.

RelativeDate Object Members

The RelativeDate object includes several useful members, each serving a unique purpose. Below are the available members:

Member NameTypeDescription
RelativeDate.dateIdstring (read-only)The ID of the relative date.
RelativeDate.endObject (read-only)The end point of the relative date.
RelativeDate.intervalObject (read-only)The interval from RelativeDate.start to RelativeDate.end.
RelativeDate.isRangeboolean (read-only)Indicates if this is a range of dates or a specific moment in time.
RelativeDate.startObject (read-only)The start point of the relative date.
RelativeDate.valuenumber (read-only)The value associated with the relative date.

Supported Script Types

The RelativeDate object is available for Client and Server scripts, making it versatile for various scripting needs.

Example Code

Here is a syntax example showing how to create a RelativeDate object and use it in a query condition:

suitescript
1// Create a relative date object for two weeks ago
2var myEndDate = query.createRelativeDate({
3 dateId: query.DateId.WEEKS_AGO,
4 value: 2
5});
6
7// Create a complex query condition using the relative date
8var myComplexCondition = myQuery.createCondition({
9 fieldId: 'trandate',
10 operator: query.Operator.WITHIN,
11 values: [query.RelativeDateRange.THREE_FISCAL_YEARS_AGO.start, myEndDate]
12});

Conclusion

The RelativeDate object significantly improves the ability to handle date-sensitive queries in SuiteScript, allowing developers to create flexible filters based on relative date calculations. Utilizing these robust features enhances query performance and the precision of data retrieval.

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • The RelativeDate object is crucial for query conditions involving time.
  • It supports both Client and Server script types.
  • Members like dateId, start, and end enhance functionality.
  • Flexible use of relative timing improves data interrogation efficiency.

Frequently Asked Questions (4)

What script types support the RelativeDate object in SuiteScript?
The RelativeDate object is supported in both Client and Server scripts, making it versatile for various scripting needs.
How do you create a RelativeDate object in SuiteScript?
To create a RelativeDate object, use the `query.createRelativeDate(options)` method, which allows you to define properties associated with the relative date.
What are the members of the RelativeDate object, and what do they represent?
The RelativeDate object includes members like `dateId`, `end`, `interval`, `isRange`, `start`, and `value`, each providing specific information about the relative date, such as its ID, start and end points, and whether it's a range or a specific moment.
Can the RelativeDate object be used to filter records based on time intervals in SuiteScript?
Yes, the RelativeDate object allows filtering records using operators like `query.Operator.AFTER`, `query.Operator.BEFORE`, and `query.Operator.WITHIN`, facilitating dynamic data filtering based on time intervals.
Source: RelativeDate Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →