0

3rd party web based workflow application. Trying to get javascript to insert todays date into a grid date field if the field is empty.

If I set the following code:

function todayDate(){

  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();

  if (dd<10) { 
    dd='0'+dd
  } 

  if (mm<10) {
    mm='0'+mm
  } 

  today = yyyy+'/'+mm+'/'+dd;
  $("#Travel_ItineraryDetails").setValue(today,1,1);
}
todayDate();

it inserts the date into the correct field. This also overwrites the date each time the user opens the form.

Grid name: Travel_ItineraryDetails

Field name: date

Field is the first field in the grid hence teh 1,1 in the .setValue command above.

RobG
  • 142,382
  • 31
  • 172
  • 209
Gunna
  • 13
  • 4
  • how does that check for the field named 'date' in the grid called 'Travel_ItineraryDetails'? – Gunna Dec 11 '17 at 05:41
  • So what's the issue? What do you expect? What do you get? – RobG Dec 11 '17 at 05:59
  • I need an if statement that will check if the field is empty and insert the date set out in the function however i'm having trouble as it is in a grid. I'm not sure how to get the if statement to look in a grid. – Gunna Dec 11 '17 at 06:14

2 Answers2

0

in grid one moment..

and with processmaker .. use $("#gridId").getValue(row, col)
(Available Version: 3.0.1.3 and later. )

Documentation here


variant without processmaker
function todayDate(){

  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();

  if (dd<10) { 
    dd='0'+dd
  } 

  if (mm<10) {
    mm='0'+mm
  } 

  today = yyyy+'/'+mm+'/'+dd;
  var elem = document.getElementById("Travel_ItineraryDetails");
  
if( elem.innerHTML =="")  
//  $("#Travel_ItineraryDetails").html(today); with jQuery
elem.innerHTML = today;
}
todayDate();
<div id=Travel_ItineraryDetails></div>

function todayDate(){

  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();

  if (dd<10) { 
    dd='0'+dd
  } 

  if (mm<10) {
    mm='0'+mm
  } 

  today = yyyy+'/'+mm+'/'+dd;
  var elem = document.getElementById("Travel_ItineraryDetails").rows[0].cells[0];
  
if( elem.innerHTML =="")  
//  $("#Travel_ItineraryDetails").html(today); with jQuery
elem.innerHTML = today;
}
todayDate();
<table id="Travel_ItineraryDetails">
    <tr class="row">
        <td class="cell"></td>
        <td class="cell">2</td>
    </tr>
    <tr class="row">
        <td class="cell">3</td>
        <td class="cell">4</td>
    </tr>
</table>
Akubik
  • 500
  • 2
  • 9
0

There are two ways to do that in ProcessMaker, One is by using Trigger and another is by writing Javascript.

The answer by Akubik is good but if you want trigger, you just need to use it in PHP code like this:

$date_field = @@date_field;
//it is my hobby to store processmaker variables in a PHP variables
if(!empty($date_field))
{
   @@date_field =  date("Y/m/d"); 
   //i force PM variable to use the date for today
  //by default processmaker is using YYYY-MM-DD
} 

Place this in a trigger and put that trigger Before Dynaform.

Liu Jin Long
  • 83
  • 1
  • 10