Fiscal Calendar - How to query to see what quarter I am in

mauricio_paloma
Tera Expert

Greetings Earthlings!

We have activated the Fiscal Calendar plugin and now we want to use it. 

Input: Today's Date

Output: The Quarter of the input

Is there a "isInFiscal" function / library that we can leverage to pull this out?

Here's the screenshot of our table below, for 'fiscal_period'.

find_real_file.png

1 ACCEPTED SOLUTION

Sunil B N
ServiceNow Employee
ServiceNow Employee

Hi Mauricio,
At the moment there are no APIs to provide that.
Nevertheless its quite straight forward to get the fiscal quarter based on the date.

var dateObj = new GlideDateTime();
var gr = new GlideRecord("fiscal_period");
gr.addQuery('fiscal_type', 'quarter');
gr.addQuery('fiscal_start_date_time', "<=", dateObj);
gr.addQuery('fiscal_end_date_time', ">=", dateObj);
gr.query();
if (gr.next()) {
    return gr;
}

Cheers,
Sunil B N
P.S: Please mark this as an answer/helpful if it was useful to you.

View solution in original post

2 REPLIES 2

Sunil B N
ServiceNow Employee
ServiceNow Employee

Hi Mauricio,
At the moment there are no APIs to provide that.
Nevertheless its quite straight forward to get the fiscal quarter based on the date.

var dateObj = new GlideDateTime();
var gr = new GlideRecord("fiscal_period");
gr.addQuery('fiscal_type', 'quarter');
gr.addQuery('fiscal_start_date_time', "<=", dateObj);
gr.addQuery('fiscal_end_date_time', ">=", dateObj);
gr.query();
if (gr.next()) {
    return gr;
}

Cheers,
Sunil B N
P.S: Please mark this as an answer/helpful if it was useful to you.

Hi Sunil,

I have a similar scenario where I need to query Fiscal Period to get the current quarter based on a field date on a form (u_entry_date).

The intent is when the u_entry_date changes, the Quarter field (u_quarter) on the form gets populated as well. I've tried flow designers to query, but it is not working.

 

var entry = current.u_entry_date;
var gr = new GlideRecord("fiscal_period");
gr.addQuery('fiscal_type', 'quarter');
gr.addQuery('fiscal_start_date_time', "<=", entry);
gr.addQuery('fiscal_end_date_time', ">=", entry);
gr.query();
if (gr.next()) {

current.u_quarter = 'quarter';
current.update();

 

Any suggestions?


Thank you.