Skip to content

Instantly share code, notes, and snippets.

@johnmjackson
Last active September 9, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmjackson/df14aaf8863d3b42ad0d to your computer and use it in GitHub Desktop.
Save johnmjackson/df14aaf8863d3b42ad0d to your computer and use it in GitHub Desktop.
This is an imaginary example of an output.js script for a 'Get Organization' method in a CRM app.
'use strict';
module.exports = function(options, done) {
// This is an imaginary example of an output.js script for a 'Get Organization'
// method in a CRM app. The CRM allows custom fields to be added to the
// organization record. I.e. special fields that are set up by the account
// administrator that are specific to their account/business.
// We've already created a method on the service object (in index.js)
// that helps us to fetch the 'schema' for custom fields that relate to
// the type of record we're dealing with here - 'organization'.
this.getCustomOutputs(options.credentials, 'organization', function(err, customFields) {
if(err) {
return done(err);
} else {
// Now we have an array like this:
// [ { id: 's763gsiwucgd', name: 'Foo'}, { id: 'l81gab452gst', name: 'Bar' }]
// ('id' is the unique reference for the field, 'name' is what the user called it)
// So we simply need to make it into a Flow XO output fields array.
var outputs = [];
customFields.forEach(function(field) {
outputs.push({
key: field.id,
label: field.name
});
});
// So now we have:
// [ { key: 's763gsiwucgd', label: 'foo'}, { key: 'l81gab452gst', label: 'bar' }]
// Which will allow the user to use these custom fields in their workflows.
done(null, outputs);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment