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

  1. Navigate to the Building portlet.

  2. Select a permit.

  3. Click the Professionals tab.

    Civic Platform displays the Professionals tab in the detail portlet

  4. Click the New button to enter the licensed professional information.

  5. 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

  1. Create a New expression and navigate to the Expression Name field.

    Civic Platform displays the New Expression fields where you define the criteria.



  2. Enter an Expression Name. This scenario uses
    Licensed Professional Validation
  3. 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
    Building/Building Permit/Commercial/All Categories
    In general, you do not need to perform this step.
  4. Select
    Script Mode
    in the Edit Mode section.

    Civic Platform re-populates the page to display the Script fields.



  5. Select
    Professional
    from the Target Portlet drop-down list.

    This step specifies that the expression takes effect in the Professional portlet for the selected record type.

  6. In the ASI Group field, select the group that contains the record type and the fields for which you want to create an expression.



  7. 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.



  8. Click the Execute Fields list picker.

    A pop-up window displays the Execute Fields list.



  9. Expand Professional and click the License # and License Type options.

    Civic Platform loads the License # and License Type options in the Execute Fields list.



  10. 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;
        }
  11. Click theValidate button to check the EMSE script for errors.

  12. Click theSubmit button.