Skip to content

Instantly share code, notes, and snippets.

View MappingKat's full-sized avatar

Katrina Engelsted MappingKat

  • Glenwood Springs, CO
View GitHub Profile
@MappingKat
MappingKat / block-4.js
Last active October 25, 2016 20:33
block-4.js
function deleteRecord(payload, done) {
payload.record = payload.data;
payload.record.form_id = "{FULCRUM SECOND FORM ID}";
// this sets up the record id from the original form to the text field in the 2nd form
payload.record.form_values['{FULCRUM ELEMENT KEY}'] = payload.record.form_values['{FULCRUM ELEMENT KEY 2}'];
delete payload.data;
var query = encodeURIComponent("SELECT _record_id AS fulcrum_id FROM \"Table Name\" WHERE my_record_id= '" + payload.record.form_values['FULCRUM ELEMENT KEY'] + "'");
request({
@MappingKat
MappingKat / block-3.js
Last active November 17, 2019 00:37
Block-3
function updateRecord(payload, done) {
payload.record = payload.data;
payload.record.form_id = '{FULCRUM SECOND FORM ID}';
// the line below equates the RECORDID() calculation field from the original form to the text field in the 2nd form
// so that we can use the query API to find the correct correct to update from the original form
payload.record.form_values['{FULCRUM ELEMENT KEY}'] = payload.record.form_values['{FULCRUM ELEMENT KEY 2}'];
delete payload.data;
var query = encodeURIComponent("SELECT _record_id AS fulcrum_id FROM \"Table Name\" WHERE my_record_id= '" + payload.record.form_values['FULCRUM ELEMENT KEY'] + "'");
request ({
@MappingKat
MappingKat / block_2.js
Last active November 17, 2019 00:36
block-2.js
function createRecord(payload, done) {
payload.record = payload.data;
payload.record.form_id = "{FULCRUM SECOND FORM ID}";
// if you have a field that does not have the same element key for both forms then you can associate the fields
// with this line (I explain what this is for in more detail in the next block):
payload.record.form_values['{FULCRUM ELEMENT KEY}'] = payload.record.form_values['{FULCRUM ELEMENT KEY 2}'];
delete payload.data;
delete payload.record.id;
request({
@MappingKat
MappingKat / block_1
Created October 25, 2016 14:05
block-1
// `express` is a minimal and flexible web application framework that helps with routing logic.
var express = require('express');
// `fulcrumMiddleware` is a library that lets you take some shortcuts for setting up Fulcrum webhooks.
var fulcrumMiddleware = require('connect-fulcrum-webhook');
// `request` allows you to make REST calls to APIS so that you can get, add, update or delete data.
var request = require('request');
// setting up the local port to listen on
var PORT = process.env.PORT || 9000;
// setting up the express framework
var app = express();
@MappingKat
MappingKat / app.js
Created October 24, 2016 20:52
block-5
var fulcrumMiddlewareConfig = {
actions: ['record.create', 'record.update', 'record.delete'],
processor: payloadProcessor
};
app.use('/', fulcrumMiddleware(fulcrumMiddlewareConfig));
// this is for decorative purposes. It adds a little HTML to the front end of your URL so that you can check to make sure things are up and running
app.get('/', function (req, res) {
res.send('<html><head><title>The Webhook Script</title></head><body><h2>is Running!</h2><p>going</p></body></html>');
@MappingKat
MappingKat / payload.js
Last active October 25, 2016 13:51
payload.js
{
id: "1371c81d-367b-45d3-9f7c-91da5de9518e",
type: "record.delete",
owner_id: "00053caf-4b6e-4c86-88b6-64695895dffe",
data: {
status: "Completed",
version: 3,
id: "7553fd44-78bb-41eb-a453-8b301ae5e52e",
form_id: "295eda4a-7795-4881-9f62-085a930b356e",
project_id: "Wetlands",
@MappingKat
MappingKat / block_1.js
Last active November 17, 2019 00:38
Block 1
// `express` is a minimal and flexible web application framework that helps with routing logic.
var express = require('express');
// `fulcrumMiddleware` is a library that lets you take some shortcuts for setting up Fulcrum webhooks.
var fulcrumMiddleware = require('connect-fulcrum-webhook');
// `request` allows you to make REST calls to APIS so that you can get, add, update or delete data.
var request = require('request');
// setting up the local port to listen on
var PORT = process.env.PORT || 9000;
// setting up the express framework
var app = express();
function updateStatus (recordID) {
var url = "https://api.fulcrumapp.com/api/v2/records/" + recordID + ".json?token=" + fulcrumAPIkey;
var options = {
"method": "GET",
"contentType": "application/json"
};
var recordJSON = UrlFetchApp.fetch(url, options);
// Update record with status info
var record = JSON.parse(recordJSON);
function updateDate (recordID, date) {
var url = "https://api.fulcrumapp.com/api/v2/records/" + recordID + ".json?token=" + fulcrumAPIkey;
var options = {
"method": "GET",
"contentType": "application/json"
};
var recordJSON = UrlFetchApp.fetch(url, options);
// Update record with wx info
var record = JSON.parse(recordJSON);
function loopThrough(records){
var myDateString = Utilities.formatDate(new Date(),"GMT", "yyyy-MM-dd");
for (var i = 0; i < records.length; i++) {
var formattedDate = records[i].updated_at.substr(0, 10);
var now = new Date();
if (formattedDate === myDateString) {
now.setDate(now.getDate() + 30);
var stringDate = Utilities.formatDate(now,"GMT", "yyyy-MM-dd");
updateDate(records[i].id, stringDate);