how can I add a criteria to a search in suitescrip...
# ask-stanley-ai
l
how can I add a criteria to a search in suitescript that searches records with datecreated in the last 24 hours? ["datecreated", "after", 24HoursAgo]
c
AI generated answer (using internal Slack threads):
To add a criteria to a search in SuiteScript that searches records with datecreated in the last 24 hours, you can use a Formula (Numeric) criteria filter. Set the Formula to
{today} - {createddate}
which returns the number of days elapsed as a floating point value, then filter on results
less than or equal to
value
1
. This will give you the records created in the last 24 hours. Here is a sample code snippet:
Copy code
javascript
var search = require('N/search');
var mySearch = search.create({
   type: "salesorder",
   filters:
   [
      ["formulanumeric: {today} - {createddate}", "lessthanorequalto", 1]
   ]
});
This code creates a search for sales orders that were created in the last 24 hours. The filter uses a formula to calculate the difference between the current date and the created date of the sales order. If the difference is less than or equal to 1 (i.e., the sales order was created within the last 24 hours), the sales order is included in the search results. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845420301
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829418063
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822995663
Please provide your feedback on this answer.