how to get date field value in the workflow

govardhantv
Kilo Contributor

Hi all,

i have a catalog item .in which(internal it ) can can share any updates on future days ,

i have created a catalog item ,in that i have two fields ,"date" and "message " ,now internal it   can selcted the "date" and   filling   "message" clicks on order now ,so that request item will be created ,so that i have desinged a workflow which will start once ritm is created .

now i have to keep condition activity   in the workflow with condition saying that if today date and time =slected date and time in the catalog filed then i should trigger a notification

i have tried writing script in condition activity it is not working ..i am new to servicenow ..i have tried all possible ways

var todayDay=today.getDayOfMonthLocalTime();

var selected_days=current.date_time_needed();

  if(selected_days.indexOf(todaysDay)>-1){

  gs.info("entered");

  return true;

  }

}

1 ACCEPTED SOLUTION

arnabwa
Giga Guru

Hi Gova,




First of all I would let you know that we do not compare dates having its time too. It is not that we cannot compare but dates accompanied with time will never give us a true result for equality condition. This is because the seconds and milliseconds never match between two date fields. So I would suggest you to compare only the Date and proceed. Here is how you can extract the dates of the fields.


In the activity field of workflow write this code (make your own changes in the field names):




var curr_date = gs.nowDateTime();// gives current date


  var created = new GlideDate();


  created.setValue(curr_date);// current date is now in the 'created' variable


  gs.log("@@@current date is : " + created);



  var selectedDate = current.u_date1.getDisplayValue();// use your own date variable in place of u_date1


  gs.log("@@@date 1 is : " + selectedDate);


now proceed comparing




Thanks,


Arnab


View solution in original post

4 REPLIES 4

palmen
Tera Guru

Don't know what your workflow look like but you can trigger a scheduled event from the workflow and set it to trigger at the time you've specified in the date field.


This event will then wait until the specified date/time before it trigger


http://wiki.servicenow.com/index.php?title=Notification_Examples#Define_a_Scheduled_Event


arnabwa
Giga Guru

Hi Gova,




First of all I would let you know that we do not compare dates having its time too. It is not that we cannot compare but dates accompanied with time will never give us a true result for equality condition. This is because the seconds and milliseconds never match between two date fields. So I would suggest you to compare only the Date and proceed. Here is how you can extract the dates of the fields.


In the activity field of workflow write this code (make your own changes in the field names):




var curr_date = gs.nowDateTime();// gives current date


  var created = new GlideDate();


  created.setValue(curr_date);// current date is now in the 'created' variable


  gs.log("@@@current date is : " + created);



  var selectedDate = current.u_date1.getDisplayValue();// use your own date variable in place of u_date1


  gs.log("@@@date 1 is : " + selectedDate);


now proceed comparing




Thanks,


Arnab


Hi arnab ,


Thanq for the reply ,how would this code work it will take system date and compare with field time if it is matched then it pass the condition


Abhinay Erra
Giga Sage

If you want to trigger a scheduled event,use gs.eventQueueScheduled().


http://wiki.servicenow.com/index.php?title=Notification_Examples#gsc.tab=0