Client Script to look for everything created after a certain date

Stacy1
Mega Guru

I have a client script where I only want to set the fields to mandatory if the item was created after 6-2017-06-02 23:59:59.

It's not working, can I not do a basic greater than script?   My alert comes up empty??? 😞

function onLoad() {

    }

var cdt = g_form.getValue('sys_created_on');

alert ("date created is " + cdt);

if   (cdt>('2017-06-02','23:59:59')){

Thanks,

Stacy

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Stacy,



Step 1: Create a display business rule and set the filter condition created date | after | date. The conditioning filter is required here so that this is only trigger per your filter defined.


Place the below line in between function template


g_scratchpad.mand = true;



Step 2: Now create the client script as



if (g_scratchpad.mand)


      {


  g_form.setMandatory('fieldname',true);


}


View solution in original post

6 REPLIES 6

Shishir Srivast
Mega Sage

Hi Stacy,



I don't think form view is applicable based upon the records, if the field is to be set as mandatory then it should be for all records.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Stacy,



Step 1: Create a display business rule and set the filter condition created date | after | date. The conditioning filter is required here so that this is only trigger per your filter defined.


Place the below line in between function template


g_scratchpad.mand = true;



Step 2: Now create the client script as



if (g_scratchpad.mand)


      {


  g_form.setMandatory('fieldname',true);


}


This worked perfectly.   Thank you so much.