简体   繁体   中英

Suitescript, How to use query.Operator.ON to get record has exact day from database?

I'm trying to get records has a birthday in [day] by using query ('N/query'). And I'm looking for using the operator "Operator.ON". However, I always get the empty list from DB. When I change from "Operator.ON" to "Operator.ON_AFTER" I can get results.

My date format is "D/M/YYYY" In DB, the record date is '1/5/2019'

The full script is attached. Please let me know the best ways to get record by an exact date.

 require(['N','N/search','N/record','N/query', 'N/currentRecord', 'N/format']);
    var query = require('N/query');
    var search = require('N/search');
    var currentRecord = require('N/currentRecord');

    var birth = currentRecord.get().getValue({
                fieldId: 'custentity_date_of_birth'
            });

    var customSearch = query.create({
                type: query.Type.CUSTOMER
            });

    var relContact = customSearch.autoJoin({
                fieldId: 'contact'
            });

            customSearch.columns = [
                customSearch.createColumn({
                    fieldId: 'Id'
                }),
                customSearch.createColumn({
                    fieldId: 'firstname'
                }),
                customSearch.createColumn({
                    fieldId: 'lastname'
                }),
                customSearch.createColumn({
                    fieldId: 'email'
                }),
                customSearch.createColumn({
                    fieldId: 'custentity_date_of_birth'
                }),
                relContact.createColumn({
                    fieldId: 'Id'
                })
            ];

    var condFName = customSearch.createCondition({
                fieldId: 'firstname',
                operator: query.Operator.IS,
                values: 'trung'
            });

            var condLName = customSearch.createCondition({
                fieldId: 'lastname',
                operator: query.Operator.IS,
                values: 'null'
            });

            var condBirth = customSearch.createCondition({
                fieldId: 'custentity_date_of_birth',
                operator: query.Operator.ON,
                values: '1/5/2019'
            });

            var condGetBirth = customSearch.createCondition({
                fieldId: 'custentity_date_of_birth',
                operator: query.Operator.EMPTY_NOT
            });

            customSearch.condition = customSearch.and(condFName, condLName, condBirth);

            var sResult = customSearch.run();
            sResult.results

the reason is my application is using GTM+7 In form, the date picker get date '1/5/2019' and passing this string to script

In backend, Netsuite get this day '1/5/2019' and parse it to GTM+7 -> 30/4/2019 and compare in data. It never match with the record '1/5/2019' in db

I tried to convert date & timezone from date picker but useless. I must hardcode date+1 day and pass to the condition then it can get exact day from DB.

You can create a saved search and the script reference the saved search. Using saved will lessen the coding and you can run the saved search in the UI to check if you are getting the right result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM