Example Expression Script
This following example illustrates how to define an expression that uses a state agency web service to validate a licensed professional.
In the example, you manually enter an EMSE script in the script mode window of Expression Builder for a selected Professional Execute Fields. The EMSE script verifies the license type and license number on a new application. The expression also updates the licensed professional license to the most current information, for example, status, expiration date, and address.
Note:
You must build or deploy a Web Service Stub to interface with the external Web Services. For more information about building a Web service stub for your agency, see the Creating an External Web Service Stub (08ACC-04275) – Accela Automation Technical Bulletin.pdf. |
To verify the licensed professional
Navigate to the Building portlet.
Select a permit.
Click the Professionals tab.
Civic Platform displays the Professionals tab in the detail portlet
Click the New button to enter the licensed professional information.
Select License Type from the drop-down list, or enter a License #.
If the license number and license type validate successfully, Civic Platform creates the new record. If the license number and license type are not valid, Civic Platform displays the EMSE error message on the Professionals tab.
To create the EMSE script to validate licensed professionals
Create a New expression and navigate to the Expression Name field.
Civic Platform displays the New Expression fields where you define the criteria.
- Enter an Expression Name. This scenario uses
Licensed Professional Validation
Select Record Detail from the Target Portlet drop-down list.
This step specifies that the expression takes effect in the Record detail portlet or application for the selected record type. This scenario uses the record type
In general, you do not need to perform this step.Building/Building Permit/Commercial/All Categories
- Select
in the Edit Mode section.Script Mode
Civic Platform re-populates the page to display the Script fields.
- Select
from the Target Portlet drop-down list.Professional
This step specifies that the expression takes effect in the Professional portlet for the selected record type.
In the ASI Group field, select the group that contains the record type and the fields for which you want to create an expression.
Use the Variables section to specify the fields affected by the expression.
Civic Platform displays ASI, Professional, Record Detail, and Session Variables in the Variables field.
Click the Execute Fields list picker.
A pop-up window displays the Execute Fields list.
Expand Professional and click the License # and License Type options.
Civic Platform loads the License # and License Type options in the Execute Fields list.
In the Script field, enter the EMSE script. The script for this scenario is:
/*----------------------------------------------------------------/ | Program : LicProfAddBefore.js | Event : LicProfAddBefore | /----------------------------------------------------------------*/ var LicProfModel = aa.env.getValue("LicProfModel"); var licenseType = LicProfModel.licenseType; var licenseNbr = LicProfModel.licenseNbr; var licenseValidateReturnCode = "0"; var licenseValidateReturnMessage = "Follow Licenses are invalid:"; if (!validateLicense(licenseType, licenseNbr)) { licenseValidateReturnCode = "-1"; licenseValidateReturnMessage += "<br>"; licenseValidateReturnMessage += " * License type: " + licenseType; licenseValidateReturnMessage += " , License number: " + licenseNbr; } // check whether something wrong if (licenseValidateReturnCode != "0") { aa.env.setValue("ScriptReturnCode", licenseValidateReturnCode); aa.env.setValue("ScriptReturnMessage", licenseValidateReturnMessage); } // check whether the licenseType and licenseNbr is valid. function validateLicense(licenseType, licenseNbr) { var accelawsUrl = 'https://www4.cbs.state.or.us/exs/bcd/accela/ws/accelaws.cfc?method=lic_valid&returnformat=json'; var client = aa.httpClient; // set url parameters var params = client.initPostParameters(); params.put('p_lic_type', licenseType); params.put('p_lic_num', licenseNbr); // do validate via web service var scripResult = client.post(accelawsUrl, params); // check the return value if (scripResult.getSuccess()) { var resultString = String(scripResult.getOutput()); //Convert to jsonObject var result = eval("("+resultString+")"); var valid = String(result["VALID"]); if (valid.toUpperCase() == "TRUE") { return true; } } else { aa.print("ERROR: Failed to validate license: " + scripResult.getErrorMessage()); return false; } return false; }
Click theValidate button to check the EMSE script for errors.
Click theSubmit button.