cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

fetch entries created in last 30 days from Datatable

MA8731174
14-Alexandrite

fetch entries created in last 30 days from Datatable

Dear Community,

    So below in attachment is my datashape of my datatable and currently i am getting all the entries in one of my service. Is there anyway that with infotable capabilities i can get entries which are created in the last 30 days. As you can see i have one of the parameter qualityCheckTimestamp which records the datetime for the entry. 

Now i would like to use pre existing function of infotable to get the entries created in last 30 days and if its not possible then i would have to iterate through all the entries to get the desired entries which would might be slow process. 

so anyone have a clue about it?

 

Thank you

 

 

Jamal8548_0-1723545679759.png

 

5 REPLIES 5
MA8731174
14-Alexandrite
(To:MA8731174)

I think i have a solution to my post. Please ignore other comments  as they have highlighted my previous error in this post and now i have edited the reply and this is solution

 

const currentDate = new Date();
const fromDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, currentDate.getDate());
    
    var query = {

          "filters": {
            "fieldName": "qualityCheckTimestamp",
            "type": "BETWEEN",
            "from": fromDate,  
            "to": Date.now() 

          } 
    };

 

request payload:

Jamal8548_0-1723547469735.png

 

Velkumar
19-Tanzanite
(To:MA8731174)

Hi @MA8731174 

 

Try below script 

let fromDate = dateAddDays(new Date(), -30);
let result = fromDate;

 

Also consider client and server timezone difference

 

/VR

Your piece of code is a JS service executed on the server, not on the client. The request payload you show is a request sent by your browser.

Please explain how these two come together.

also, when running the code, you can easily log.warn into scriptlog and check there if your date computation is correct, e.g. log.warn("fromDate="+fromDate);

MA8731174
14-Alexandrite
(To:Rocko)

Thanks for highlighting it actually first i have created two input parameters of the service and was looking into them from network tab but now i dont need them and i can give directly min and max date which i have done now and yes i would use log.warn level logger to see. That was the confusing part for me and my code above is all fine getting right dates which i have stated above.

Hello @MA8731174

 

It looks like you have some responses from some community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.

Announcements


Top Tags