Setting System Fields using Script Field Processor

In this example, we'll be setting the due date and description fields in Jira using Script Field Processor.

The basic functionality is to set the due date a week from the current time and if the body of the mail is empty, we'll use a default/short message.

function nextweek(){ var today = new Date(); var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7); return nextweek; } function toLocalIsoDateString(date) { function pad(n) { return n < 10 ? '0' + n : n } var localIsoDateString = date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()); return localIsoDateString; } if (toAddresses) { for (i =0 ; i< toAddresses.length ; i++) { if (toAddresses[i].getAddress().toLowerCase() == 'special@example.com'.toLowerCase()) { if (body === '') { resultMap.put("description", "Email import"); } resultMap.put("dueDate", toLocalIsoDateString(nextweek())); } } }

Do note the following:

  • The description + due date is set if the receiver is special@example.com

  • Description is set to Email import if there is no body in the mail