Pages

Monday, February 27, 2017

Episode 524: Automation of Work with Server-side JavaScript

Utilization of programming knowledge

"Script Step" is a kind of "automated Step" within a Business Process.

These are Steps for automatically executing "program processing", such as, for example;
  • with reference to "attendance time" and "leaving time" entered in the upstream process,
  • automatically calculates "working time" ({leaving time} - {attendance time}).
Conversely, if you incorporated such a Script Step into the Daily report flow, employees do not have to fill in "hours worked " each time.

What can be done?

Automatic processing performed on the Workflow platform is so-called "Server side processing".

In other words, when an Issue flowing through a Business Process reaches the "Script step", data are automatically referenced and updated. All processing is executed while human beings are not aware or concerned.

The program code to be set there will be a configuration like;
  • starting with "to reference business data",
  • via "various arithmetic processing",
  • end with "updating business data".

What kinds of "operations" are possible?

For example, in the case of "Questetra BPM Suite" which is a cloud based Workflow product, it is given the specification as "(*) capable of setting Server-side JavaScript (ECMA Script)". And the following operations are available.
  • Basic numerical data operation (four arithmetic operations, square root, exponent, round-off, random number...)
  • Basic character string data manipulation (join, split, reshape, extract, replace, search ...)
  • Basic date and time data operation (addition, subtraction, progress calculation, day of week judgement, Japanese calendar conversion ...)
  • Generation and analysis of JSON data
  • Generation and analysis of XML data
  • Sending HTTP request (data GET, data POST, OAuth2 communication, Basic authentication ...)
  • Send SMTP request (send email, attachment file generation, convert character code ...)
* You can also use Java methods that can be handled by the Rhino engine, and Questetra extension methods. [R2300]
※ The details are HERE and THERE.

[Hours-worked report-Hours and minutes]



Example of program code

In the Script step of "Hours-worked calculation" in this Workflow, the following program code is set, for example.

When the "2. Leave time report" is completed by an employee, the Issue reaches the "Hours-worked calculation" Step. And "Hours-worked" (Numeric type data) such as "8.11 (h)" and "7.96 (h) Is added

//// == Retrieving ==
var workStart = data.get("6");
var workEnd = data.get("7");
// com.questetra.bpms.util.AddableTimestamp
var workBreak = data.get("8") - 0; // (h) number

//// == Calculating ==
// java.sql.Timestamp: long getTime()
// Returns the number of milliseconds since Jan 1, 1970 GMT
var intervalMilliSec = workEnd.getTime() - workStart.getTime() ;
var intervalHour = Math.ceil( intervalMilliSec / 10 / 3600 ) / 100 ;
// second places of decimals
var workHour = intervalHour - workBreak ;

//// == Updating ==
retVal.put("9", java.math.BigDecimal( workHour ) );

Maintenance of Script step

If you want to change it to calculate not only Numeric type, such as "8.11 (h)" or "7.96 (h)", but also to output String type data such as "8:07" or "7:58", you need to edit the program code.

(Codes added to "line #15 to #18" and "line #22")

//// == Retrieving ==
var workStart = data.get("6");
var workEnd = data.get("7");
// com.questetra.bpms.util.AddableTimestamp
var workBreak = data.get("8") - 0; // (h) number

//// == Calculating ==
// java.sql.Timestamp: long getTime()
// Returns the number of milliseconds since Jan 1, 1970 GMT
var intervalMilliSec = workEnd.getTime() - workStart.getTime() ;
var intervalHour = Math.ceil( intervalMilliSec / 10 / 3600 ) / 100 ;
// second places of decimals
var workHour = intervalHour - workBreak ;

var h = Math.floor( workHour );
var m = Math.floor( (workHour - Math.floor( workHour ) ) * 60 );
var mm = ( "0" + m ).slice(-2);
var workHourStr = h + ":" + mm;

//// == Updating ==
retVal.put("9", java.math.BigDecimal( workHour ) );
retVal.put("12", workHourStr );

Notes for using Script step

"Automating Business Processes" will greatly contribute to productivity improvement.

However, programming knowledge is absolutely necessary for maintenance of the Script Steps.

When utilizing the Script step in a Business Processes, it is important to discuss deeply about "Total operation including maintenance" with reference to the Usage example of Script step.

[Hours-worked report-Hours and minutes:"1. Attendance report" screen]

[Data Items list]


[Free Download]
<Similar Models>
<<Related Articles>>

[Japanese Entry (ε’Œζ–‡θ¨˜δΊ‹)]