Asite enables the generation of custom XML output from existing form data within the project, with the help of workflow system tasks. Below are the steps for configuring workflow to generate XML output:
Step 1: Create a system task with Groovy script configured to generate custom XML output from form data.
Below is a snippet of a sample groovy script:
|
Groovy script configuration includes 3 main stages:
1. Defining information that needs to be read
|
The script highlighted above is an example where the administrator maps the information that needs to be read from the form.
Below is the general syntax for retrieving any information from the form, syntax contains 2 main parameters as explained below:
|
'Variable Name' could be any name the administrator can use to identify the information.
Include a function to read the relevant form's information.
The system allows user to read standard or custom form fields defined within the form:
To read standard fields i.e. any field captured by default by the Asite system. (e.g. Title, Form Originator, Form Created Date, etc...), use the functions to extract the standard field as mentioned below:
formVo.getProjectName() – To read project name
formVo.getFormCodeNum() – To read form code
Click here to learn more about other standard functions.
Finally, the syntax to read a system field within the Groovy script will look like:
dataMap.put("PROJECT_NAME", formVo.getProjectName()); //
This will read the project's name
dataMap.put("FORM_ID", formVo.getFormCodeNum()); // This will read form ID e.g. EMP001
To read custom fields i.e. any field placed with the form design other than standard fields( e.g. Employee Name, Employee Email ID, Employee Address, etc...), use the formService function as mentioned below to extract custom field information:
formService.getFormFieldValuesFromXML(inputXml, "<<Field Name>>"));
The administrator can replace the ‘Field Name’ with the actual field name from the form design.
Finally, the syntax to read a custom field within the Groovy script will look like:
dataMap.put("First_Name", formService.getFormFieldValuesFromXML(inputXml, "First_Name")); // This will read the data from field named ‘First_Name’
dataMap.put("Last_Name", formService.getFormFieldValuesFromXML(inputXml, "Last_Name")); // This will read the data from field named ‘Last_Name’
2. Defining the output format of the XML
|
The script above exemplifies how an administrator can specify the expected output format tags for the XML output. The general syntax to define the output format is:
<’TagName’> ##Variable Name </’TagName>
The administrator has to mention the mapping ‘Variable Name’ from the definitions mentioned in the section above. They can add as many XML tags as are required within the final XML output. Finally, the syntax for the output format of XML within the Groovy script will look like this:
<EMPLOYEE> <PROJECT>##PROJECT_NAME</PROJECT> <PROJECTID>##FORM_ID</PROJECTID> <FNAME>##First_Name</FNAME> <LNAME>##Last_Name</LNAME> </EMPLOYEE>
3. Defining email body and recipient of email
|
The administrator can configure the Groovy script to define the body and recipients of the email.
The administrator will have to define the email content in the variable for ‘emailBody’, and then use that variable in the function. Below is an example of defining content within the email body:
String emailBody = "Hi, <BR/><BR/> A new employee has joined Asite. <BR/><BR/> Thanks";
The administrator can define the recipient of the email, multiple recipients can be added as recipients. Below is an example of defining an email recipient:
List<String> toRecipient = new ArrayList<>();
toRecipient.add("email1@example.com"); // The mentioned recipient will be main recipient of email
toRecipient.add("email2@example.com");// The mentioned recipient will be main recipient of email
List<String> cCRecipient = new ArrayList<>();
cCRecipient.add("email3@example.com"); // The mentioned recipient will be copy recipient of email
Administrator will then have to use the variable in the relevant functions in the Groovy script above, below are the final resultant Groovy script function replaced with the variables:
mailDataMap.put(IGroovyConstant.RECEIPIENT_ADMINISTRATORS, toRecipient);
mailDataMap.put(IGroovyConstant.CC_RECEIPIENT_ADMINISTRATORS, cCRecipient);
mailDataMap.put(IGroovyConstant.SUBJECT, "Employee Information"); //This is where administrator will be able to define the email subject
mailDataMap.put(IGroovyConstant.MAIL_BODY, emailBody);
Step 2: Create a workflow trigger on the required form to use the system task as configured in the previous step.
Step 3: Perform the task as per trigger configuration to execute the workflow system task.
Next Article: Push issues on a Federated Model to 3D Repo