Skip to content

Instantly share code, notes, and snippets.

@MappingKat

MappingKat/block-3.js

Last active Nov 17, 2019
Embed
What would you like to do?
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 ({
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(httpResponse, body);
body = JSON.parse(body);
console.log(body['rows'][0]['fulcrum_id']);
if (body['rows'][0] && body['rows'][0]['fulcrum_id']){
request({
method: 'PUT',
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('PUT', err)
console.log('PUT', body);
});
};
done();
});
delete payload.record.id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.