How to catch an exception in a Netsuite saved search formula? - netsuite

I have a saved search that looks at a custom text field on a Sales Order. The custom field should contain an ISO date. I want to get all records where that date is greater than today. My first attempt was to try Formula(Date) with the formula below and condition "is greater than today"
TO_DATE({custbody_est_delivery}, 'YYYY-MM-DD')
However this gave me an "Unexpected Error" when I tried to do the search. I worked out this was because not every record has an ISO date, some are null and some have been edited to contain some non-date data. It seems that if any row returns an error the whole saved search fails. I therefore want to exclude anything that doesn't parse as a date from my search. However, I could find no way of catching an exception from the TO_DATE function. For the moment I have:
CASE WHEN REGEXP_LIKE({custbody_est_delivery},'(\d{4})-(\d{2})-(\d{2})') THEN TO_DATE({custbody_est_delivery}, 'YYYY-MM-DD')ELSE TO_DATE('2099-12-31', 'YYYY-MM-DD') END
This works, but it is a horrible hack and would fail if someone e.g. wrote in '9999-99-99' in the field.
How can I catch exceptions in a Netsuite saved search formula? I'm looking for something like the pseudocode below:
IFERROR(TO_DATE({custbody_est_delivery}, 'YYYY-MM-DD'), <do something sensible>)

You can use the NVL2 function to conditionally take care of any empty field values.
e.g.
NVL2({custbody_est_delivery}, TO_DATE({custbody_est_delivery}, 'YYYY-MM-DD'), '')
See the Help page titled SQL Expressions for all of the formula functions available to you.
Personally I'd say any field values that are invalid dates are a data problem and should be corrected with a mass update or CSV import, and validation rules should be added to your custom field such that no invalid dates are allowed.

Related

Power Automate - Compare StartDate to current date?

We are looking to compare the calendar start date with the current date in flow. Currently we are pulling the start date through a filter query like this:
formatDateTime('EventDate','M-d-yyy hh:mm')
and comparing to this:
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I am getting this error currently: "Unable to process template language expressions in action 'Get_items' inputs at line '1' and column '17987': 'In function 'formatDateTime', the value provided for date time string 'EventDate' was not valid. The datetime string must match ISO 8601 format."
Any help on this would be greatly appreciated!
You could Initialize a variable like the following below and then do a IF condition.
#{add(div(sub(ticks(utcNow()),ticks('1900-01-01')),864000000000),2)}
I test with the same formula to convert event start date and it works fine in my end. The if condition returns correct result on different conditions.
Here is the logic of my demo flow, please have a check:
I use get item to get the start date of a certain event in the calendar list and convert the start time dynamic content to the format I need. Almost same with yours.
According to the error message, it seems the format of the event date column is not in the supported format. Would you like to provide the settings of your event date column? I test with the default start time column and a custom date & time column of default settings. Both of them works fine with the flow above.
Update:
The two formulas used are displayed below:
formatDateTime(outputs('Get_item')?['body/Event_x0020_Date'],'M-d-yyy hh:mm')
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I just directly use the outputs of the data compose action in the if condition
What worked for me was to build a sequence of numbers with the dates being ordered by day, month and year this way, when converting to integer, it's easy to compare
int(formatDateTime(utcNow()),'yyyyMMdd'))
if you need add day for exemple, you can use
int(formatDateTime(addDays(utcNow(),variables('extraDays')),'yyyyMMdd'))
and the other date like this
int(formatDateTime(variables('FinalDate'),'yyyyMMdd'))
Based on your example, you can put hours and minutes without any problems, just remove the special characters and spaces
but by the definition of the error you are having, I believe it is because of the way you are writing the variable

NetSuite Saved Search Calculate Date Difference Between Two Related Records

I'm trying to calculate the difference in days between an Invoice Date and the Date it was emailed out on a Saved Search.
I have a saved search created where I can see both the Invoice date (trandate) as well as the email date (messages.messagedate) but when I try to put this into a formula I keep getting a "field not found error".
I'm new to NetSuite and I also don't know a lot of SQL so I'm sure it's something basic I'm missing but here's what I have tried:
Formula (Date): TRUNC({messages.messageDate}-{transaction.tranDate}) || ' days '
Formula (Numeric): ROUND({message.messageddate}-{transaction.trandate})
I've tried "messages." and "message." and I've tried transaction. and without "transaction.".
I think I'm just missing the exact structure I need to use to reference the fields on two separate but connected records.
Please assist!
Please use Formula numeric and try with this formula
ABS(TO_DATE({messages.messagedate})-TO_DATE({trandate}))

Can someone help me with Exception occurred calling method NotesDatabase.FTSearch(string)

I'm trying to do a database full text search and struggling to get it to work.
Since I'm working with date fields, I deleted my full text index, set all my blank date fields to a fictitious date (3/15/2050), compacted the db and then rebuilt the full text index.
However, I am still getting the error for this query string:
(FIELD Form CONTAINS 'Opp') AND (FIELD Topic CONTAINS 'A') AND (FIELD DateTeam >= 3/1/2019) AND (FIELD DateTeam <= 3/31/2019)
I didn't have the single quotes in there initially, but tried it as a suggestion from another post. I also tried putting # before and after my dates, but no luck there either.
What am I missing? My customer is getting frustrated.
You didn't post the verbiage in the exception, nor say what Domino version you were using, so this is somewhat guesswork.
It could be that the UNK table (Domino's internal field catalog) thinks the field is a string field. The first value stored in a field is the type that the FT index uses to determine the indexed data type. Of course any type can be stored in the NSF data but the FT code tries to limit this type of search to fields it believes will work.
Now if those CONTAINS values are actually = values, then DQL can help you. We'll be putting CONTAINS as a verb into DQL in V11, but it (DQL) can certainly perform your date range term. Just a thought.
-John Curtis
This might help: https://www-10.lotus.com/ldd/dominowiki.nsf/dx/full-text-syntax
As far as I know date values must be in [] to work.
A good start is to test your formula in the client with the FT search function instead of altering your code.
By the way: you can shorten your formula omitting the FIELD keyword and putting the field name also in [].
I tried this in my mail database:
(FIELD Form CONTAINS "Memo") AND (FIELD Subject CONTAINS "the") AND (FIELD PostedDate >= 3/1/2019) AND (FIELD PostedDate <= 30/6/2019)
And it works correctly. So double quotes instead of single, and you might have to check whether your date format corresponds with the server's.
The approach I was taking was correct. The problem, however, was that my update agent to set all the date fields had a typo in it so it wasn't setting the right fieldnames to dates. My oversight. Once I found that and corrected it, I retraced my steps and it all works as intended now. Thank you to all for helping me find the solution.
For anyone else, I took these steps:
Open database properties and delete the full text index
Run this command on the console to compact the db: lo compact folder/db.nsf -c
Run an agent against all the docs to set the date fields to a fictitious date
Open database properties again and create a new full text index
When completed, run this command on the console: load updall -f folder/db.nsf
Run the agent again to reset the fictitious dates to blanks

What is the correct way to add a Date Filter to a scripted search (SuiteScript 1.0)?

I have a script built search in SS1.0 that includes a date range filter, however some transactions continue to be included despite their {trandate} being outside the given range.
I have tried both adding filter objects, and using a filter Expression.
Currently it looks like:
filters.push(new nlobjSearchFilter('trandate',null,'onorafter',startdate));
filters.push(new nlobjSearchFilter('trandate',null,'onorbefore',statementdate));
Which should result in retrieving transactions between start date and statementdate inclusive.
Yet, still get results outside the range (ie, before the startdate)
Try below code
filters.push(new nlobjSearchFilter('trandate',null,'within',startdate,statementdate));
Both of those should work. If you have a real dates though make sure you convert them:
filters.push(new nlobjSearchFilter('trandate',null,'onorafter',nlapiDateToString(startdate)));
filters.push(new nlobjSearchFilter('trandate',null,'onorbefore',nlapiDateToString(statementdate)));

Format a date like "20110822" in Google Open Refine (or Excel)?

I have a dataset that has two different date formats in the same column. Some are formatted like:
2008-05-15T00:00:00Z
and others are formatted like:
20090804
Google Open Refine will recognize the first type as a date and will sort and allow me to perform other operations on it. I can't figure out how to format the second type into a date. A transformation of:
value.toDate()
throws an error, as does most everything else I try. This seems like a simple problem but Googling is not helping.
Hope it helps (might not!) but with 20090804 in A1:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
should return a value formatted as a recognisable date.
Might be wrapped in a condition like so:
=IF(LEN(A1=8),DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)),A1)
such that either the first format is returned or the alternative version, according to requirement.

Resources