Last active
November 17, 2019 00:37
-
-
Save MappingKat/e721487fb9bb1d8ebfe886f3da542fb6 to your computer and use it in GitHub Desktop.
Block-3
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 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