Skip to main content

Hi, I am new to Javascript and while finding another article helpful, I need some assistance. I am adding an Inline snippet and I would like the “Available_to__c” and “Available_from__c” to be green and red if the “Available_to__c” date is passed TODAY.

Here is what you would do. 

Step 1.  Add the Available_from__c and Available_to__c fields to your model and to your table. 

In the field properties change the rendering properties to “custom”  and add a name of your choosing there.  I used OverDue

85a93e09bc26b5ea8fb5624a4aecfd9124edb289.png

Step 2.  Go to resources and add a new Javascript resource.  
- The type should be “In-Line (Snippett)” 
- The name should be the same name you 

The code should be somthing like this: 


$ = skuid.$;<br>// get value of the Avaialable_to__c field in current row var field = arguments 0];<br>var value = field.model.getFieldValue(field.row,'Available_to__c');&nbsp; //translate to Javascript Date<br>var jsDate = skuid.time.parseSFDate(value);<br> //get current date and push time back to beginning of day var currentDate = new Date();<br>currentDate.setHours(0,0,0,0);<br> //compare dates. if(field.metadata.accessible){<br>&nbsp; &nbsp; if(jsDate &lt; currentDate){<br> // do CSS stuff here...<br>&nbsp; &nbsp; &nbsp; &nbsp; field.element.css({'color':'#F22'});<br>&nbsp; &nbsp; } //put updated css into Skuid field renderer<br>&nbsp; &nbsp; skuid.ui.fieldRenderers.field.metadata.displaytype]afield.mode](field,value);<br>}&nbsp;


This should work for you. 

Note:  If the field ‘avaialble_to__c’ is a date time field you will need to adjust your code where you translate to a Javascript date.  It should read: 


var jsDate = skuid.time.&nbsp;parseSFDateTime(value);

This is how it will look: 

ea92acc3f24cfd7a8c69b7d435b6572344a86827.png