I need help with Get
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 05:40 AM
// Função para formatar a data no padrão que a API espera (YYYY-MM-DD HH:mm:ss)
const formatDate = (date: Date): string => {
return format(date, 'yyyy-MM-dd HH:mm:ss');
};
// Pegando o início e o fim do dia atual (meia-noite até 23:59:59)
const inicioDia = startOfDay(new Date()); // Meia-noite de hoje
const fimDia = endOfDay(new Date()); // 23:59:59 de hoje
console.log(inicioDia,fimDia)
// Formate as datas
const startDia = formatDate(inicioDia); // Meia-noite de hoje
const endDia = formatDate(fimDia); // 23:59:59 de hoje
// Crie a query combinada (busca por `opened_at` ou `sys_updated_on` no dia de hoje)
const betweenOpenedAt = `opened_atBETWEEN${startDia}@${endDia}`;
const betweenUpdatedAt = `sys_updated_onBETWEEN${startDia}@${endDia}`;
const betweenCloseAT = `closed_atBETWEEN${startDia}@${endDia}`
// Comando que combina as duas condições com OR
//const dateQuery = `${betweenOpenedAt}^OR${betweenUpdatedAt}^OR${betweenCloseAT}`;
const dateQuery = `${betweenOpenedAt}`;
console.log(dateQuery)
I'm creating a URL to retrieve data from the Incident table, and I want everything that was created, updated or closed on the current day (today). The date format I'm returning is this:
opened_atBETWEEN2024-10-01 00:00:00@2024-10-01 23:59:59
But for some reason I'm retrieving data from yesterday too, and I only want today's data. Can anyone help me? My URL is like this:
export const urlIncident = `${baseUrlIncident}?sysparm_query=${dateQuery}^${orderby}&${limit}`;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 06:40 AM
Do you not have a ServiceNow admin who can tell you? If you send the following query, do you get unexpected results? Below is the default time filter for "Today"
opened_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 06:43 AM
No man, what happens is, my work has a demand for servicenow, so I need to extract the data from the endpoint that was given to me, collecting the data from "today", every day, that's all I know, and I'm doing everything through JS in vsccode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 07:29 AM
// Crie a query combinada (busca por `opened_at`, `sys_updated_on` ou `closed_at` no dia de hoje)
const betweenOpenedAt = `opened_atBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
const betweenUpdatedAt = `sys_updated_onBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
const betweenClosedAt = `closed_atBETWEENjavascript:gs.dateGenerate('${startDia}')@javascript:gs.dateGenerate('${endDia}')`;
// Comando que combina as duas condições com OR
const dateQuery = `${betweenOpenedAt}^OR${betweenUpdatedAt}^OR${betweenClosedAt}`;
I THINK IT'S SOLVED, I asked chatgpt to help me and he fixed the url, I tested it in postman and it's ok