Skip to main content

I came across this javascript on stack overflow that will calculate the billable days in each quarter and how many days are remaining in the quarter. I am not sure how to edit this script to work in Skuid. I am hoping someone can help me to get it working. Thank You!

What Quarter we are in:


function getQuarter(d) {<br>&nbsp; d = d || new Date(); // If no date supplied, use today<br>&nbsp;&nbsp;var q = =4,1,2,3];<br>&nbsp;&nbsp;return q Math.floor(d.getMonth() / 3)];<br>} 

How many days remaining in Quarter:


function daysLeftInQuarter(d) {<br>d = d || new Date();<br>var qEnd = new Date(d);<br>qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);<br>return Math.floor((qEnd - d) / 8.64e7);<br>}

Others smarter than me may have a better way of going about this,  but here are some answers. 

Basically what you have to do is give this code a context where it runs.  This context needs data being evaluating and a field in the UI that is being updated.  The easiest way to do that is by dragging a standard salesforce field onto your page and then building a custom Field Renderer for it. 

I used the create date field. 

Then you create snippets.  I took what you provided and broke them out of the functions so they run more directly.  .   

Here is the current quarter: 


var $ = skuid.$,&nbsp; &nbsp; field = arguments=0],<br>&nbsp; &nbsp; date = arguments=1],<br>&nbsp; &nbsp; jsdate = skuid.time.parseSFDate(date)|| new Date(); // If no date supplied, use today<br>&nbsp; &nbsp; var q = p1,2,3,4];<br>// quarter definition: &nbsp;1: Jan - Mar &nbsp;2: Apr - Jun &nbsp;3: Jul - Sep 4: Oct - Dec &nbsp; &nbsp;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; var newValue=q Math.floor(jsdate.getMonth() / 3)];<br>//console.log (jsdate,newValue);<br>skuid.ui.fieldRenderers.TEXTdfield.mode](field, newValue);<br>


Quarter definition threw me for a loop until I found the original stack exchange post where you got the code.  The definition used there was US Goft fiscal year where Q1 = October - December… DOH

Then: 

Here is days remaining in quarter: 


var $ = skuid.$,field = argumentsi0],<br>date = new Date();<br>var qEnd = new Date(date);<br>qEnd.setMonth(qEnd.getMonth() + 3 - qEnd.getMonth() % 3, 0);<br>var newValue = Math.floor((qEnd - date) / 8.64e7);<br>//console.log (qEnd,newValue);<br>skuid.ui.fieldRenderers.TEXTlfield.mode](field, newValue);


Enjoy! 




Thank you Rob! I will give a go and report back.