query.createRelativeDate(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a query.RelativeDate object that represents a date relative to the current date.

Use this method to create a query.RelativeDate object to use as part of a query condition. After you create a query.RelativeDate object, you can use it directly in the values parameter of Query.createCondition(options) or Component.createCondition(options).

When you call this method, the options.dateId parameter determines the relative date that is created. The options.dateId parameter uses values from the query.DateId enum, and these values describe potential dates relative to the current date. Use them along with the options.value parameter to create a relative date. For example, to create a relative date that represents the date three weeks before the current date, call query.createRelativeDate(options) with an options.dateId value of query.DateId.WEEKS_AGO and an options.value value of 3. To create a relative date that represents the date three weeks after the current date, call query.createRelativeDate(options) with an options.dateId value of query.DateId.WEEKS_FROM_NOW and an options.value value of 3.

Returns

query.RelativeDate

Supported Script Types

Client and server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/query Module

Sibling Module Members

N/query Module Members

Since

2019.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.dateId

string

required

The ID of the relative date to create.

Use the query.DateId enum to set this value.

options.value

number

required

The value to use to create the relative date.

This value depends on the value that you specify for options.dateId. For example, to create a relative date that represents the date five days before the current date, use an options.value value of 5 and an options.dateId value of query.DateId.DAYS_AGO.

Errors

Error Code

Thrown If

INVALID_DATE_ID

The specified value for options.dateId is not a value from the query.DateId enum.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/query Module Script Samples.

            // Add additional code
...
var myTransactionQuery = query.create({ type: query.Type.TRANSACTION
}); var myRelativeDate = query.createRelativeDate({ dateId: query.DateId.DAYS_AGO, value: 5
}); myTransactionQuery.condition = myTransactionQuery.createCondition({ fieldId: 'trandate', operator: query.Operator.WITHIN, values: [query.RelativeDateRange.THREE_FISCAL_YEARS_AGO.start, myRelativeDate]
});
...
// Add additional code 

          

Related Topics

N/query Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices