Skip to content

Instantly share code, notes, and snippets.

@MappingKat
Last active November 17, 2019 00:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MappingKat/e721487fb9bb1d8ebfe886f3da542fb6 to your computer and use it in GitHub Desktop.
Save MappingKat/e721487fb9bb1d8ebfe886f3da542fb6 to your computer and use it in GitHub Desktop.
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