Last active
October 25, 2016 20:33
-
-
Save MappingKat/ead535f8bd493497e366c49d9773f863 to your computer and use it in GitHub Desktop.
block-4.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | |
method: 'GET', | |
url: 'https://api.fulcrumapp.com/api/v2/query/?format=json&q=' + query, | |
headers: { | |
'X-ApiToken': '{API TOKEN}', | |
'User-Agent': 'request' | |
} | |
}, | |
function (err, httpResponse, body) { | |
console.log(err, body); | |
console.log('before', body); | |
body = JSON.parse(body); | |
console.log('after', body); | |
if (body['rows'][0] && body['rows'][0]['fulcrum_id']){ | |
request({ | |
method: 'DELETE', | |
url: 'https://api.fulcrumapp.com/api/v2/records/' + body['rows'][0]['fulcrum_id'] + '.json', | |
json: payload.record, | |
headers: { | |
'X-ApiToken': '{API TOKEN}' | |
} | |
}, | |
function (err, httpResponse, body) { | |
console.log('DELETE', body); | |
}); | |
}; | |
done(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment