Middleware Services for BULLHORN® Form Triggers
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
public
server
.gitignore
README.md
gruntfile.js
index.js
package.json

README.md

form-trigger-server

Here is a starter kit for writing Form Triggers against Bullhorn's REST API.

Requirements:

Installation

$ git clone git@github.com:bullhorn/form-trigger-server.git
$ cd form-trigger-server
$ npm install
$ npm start

Getting Started

Simple Triggers are provided in server/middleware/triggers.js and are enabled to routes in server/middleware/index.js. To create a validation endpoint you could create a new file called validate.js.

export default {
    validate(request, response) {
        let packet = request.body,
            today = new Date().getTime();
        
        // Check if the start date is today or later
        if( today <= packet.startDate ){
            response.send({
                result: true // Packet looks good, lets save it.
            }); 
        } else {
            response.send({
                result: false, // Set the result to false to prevent the record from saving.
                error: "Can't create a record that starts in the Past!"
            }); 
        }
    }
}

Then you just need to add a route in server/middleware/index.js like so:

import validations from './validate';
...
middleware.post('/trigger/validate', validations.validate);

How can i change data?

To create a form trigger that will change the packet that is saved, create a file called manipulate.js.

export default {
    manipulate(request, response) {
        let packet = request.body;
        
        // Check if the start date is today or later
        if( packet.salary > 100000 ){
            packet.billRate = 0.12;
        } else if( packet.salary > 50000 ){
            packet.billRate = 0.15;
        }
        
        response.send({
            result: true,
            returnValues: packet
        }); 
    }
}