mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Website: send start flow responses to CRM (#21485)
Changes: - Updated save-questionnaire-progress to send a formatted string of a user's start questionnaire responses to the update-or-create-contact-and-account helper - Updated the update-or-create-contact-and-account helper to set getStartedResponses on contact records.
This commit is contained in:
parent
47a5d4e38f
commit
0007351602
2 changed files with 23 additions and 7 deletions
|
|
@ -187,7 +187,20 @@ module.exports = {
|
|||
psychologicalStage = '2 - Aware';
|
||||
}//fi
|
||||
}//fi
|
||||
|
||||
// Set the user's answer to the current step.
|
||||
questionnaireProgress[currentStep] = formData;
|
||||
// Clone the questionnaireProgress to prevent any mutations from sending it through the updateOne Waterline method.
|
||||
let getStartedProgress = _.clone(questionnaireProgress);
|
||||
let questionnaireProgressAsAFormattedString = undefined;// Default to undefined.
|
||||
// Using a try catch block to handle errors from JSON.stringify.
|
||||
try {
|
||||
questionnaireProgressAsAFormattedString = JSON.stringify(getStartedProgress)
|
||||
.replace(/[\{|\}|"]/g, '')// Remove the curly braces and quotation marks wrapping JSON objects
|
||||
.replace(/,/g, '\n')// Replace commas with newlines.
|
||||
.replace(/:\w+:/g, ':\t');// Replace the key from the formData with a color and tab, (e.g., what-are-you-using-fleet-for:primaryBuyingSituation:eo-security, » what-are-you-using-fleet-for: eo-security)
|
||||
} catch(err){
|
||||
sails.log.warn(`When converting a user's (email: ${this.req.me.emailAddress}) getStartedQuestionnaireAnswers to a formatted string to send to the CRM, and error occurred`, err);
|
||||
}
|
||||
// Only update CRM records if the user's psychological stage changes.
|
||||
if(psychologicalStage !== userRecord.psychologicalStage) {
|
||||
// Update the psychologicalStageLastChangedAt timestamp if the user's psychological stage
|
||||
|
|
@ -199,6 +212,7 @@ module.exports = {
|
|||
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
|
||||
organization: this.req.me.organization,
|
||||
psychologicalStage,
|
||||
getStartedResponses: questionnaireProgressAsAFormattedString,
|
||||
contactSource: 'Website - Sign up',
|
||||
}).exec((err)=>{
|
||||
if(err){
|
||||
|
|
@ -207,11 +221,6 @@ module.exports = {
|
|||
return;
|
||||
});
|
||||
}//fi
|
||||
// TODO: send all other answers to Salesforce (when there are fields for them)
|
||||
// Set the user's answer to the current step.
|
||||
questionnaireProgress[currentStep] = formData;
|
||||
// Clone the questionnaireProgress to prevent any mutations from sending it through the updateOne Waterline method.
|
||||
let getStartedProgress = _.clone(questionnaireProgress);
|
||||
// Update the user's database model.
|
||||
await User.updateOne({id: userRecord.id})
|
||||
.set({
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ module.exports = {
|
|||
'Website - Sign up',
|
||||
],
|
||||
},
|
||||
getStartedResponses: {
|
||||
type: 'string',
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
|
@ -52,7 +56,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
|
||||
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, contactSource, description}) {
|
||||
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, contactSource, description, getStartedResponses}) {
|
||||
// Return undefined if we're not running in a production environment.
|
||||
if(sails.config.environment !== 'production') {
|
||||
sails.log.verbose('Skipping Salesforce integration...');
|
||||
|
|
@ -96,6 +100,9 @@ module.exports = {
|
|||
if(psychologicalStage) {
|
||||
valuesToSet.Stage__c = psychologicalStage;// eslint-disable-line camelcase
|
||||
}
|
||||
if(getStartedResponses) {
|
||||
valuesToSet.Website_questionnaire_answers__c = getStartedResponses;// eslint-disable-line camelcase
|
||||
}
|
||||
if(description) {
|
||||
valuesToSet.Description = description;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue