Skip to content

Instantly share code, notes, and snippets.

@johndowns
Created January 2, 2018 20:10
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 johndowns/414220c68b810781b5de5c7a0d1c3d21 to your computer and use it in GitHub Desktop.
Save johndowns/414220c68b810781b5de5c7a0d1c3d21 to your computer and use it in GitHub Desktop.
function getCustomerId(document) {
// try to get the customer ID from the new format first
if (document.customer != undefined && document.customer.id != undefined) {
return document.customer.id;
}
// if that didn't work, try to get the customer ID from the old format
if (document.customerId != undefined) {
return document.customerId;
}
// if neither are present, that is an error
throw new Error("Document with id " + document.id + " does not contain customer ID in recognised format.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment