Using Javascript in TextExpander Snippets

I am trying to use JavaScript in a snippet but to keep it simple, I will use one field that is a drop down. After making the selection, I would like the script to fill in the contact information.

For some reason, when I try and embed the script it just displays it.

Here is a very simplistic code that I am trying to execute.

%fillpopup:name=SalesPerson:default=Mike Jones:Mike Jones:Matt Smith%

%script:javascript
// Define the contact information for each salesperson
const contactInfo = {
“Mike Jones”: {
phone: “555-1212”,
email: “mike.jones@emailaddress”
},
“Matt Smith”: {
phone: “222-1212”,
email: “Matt.smith@emailaddress”
}
};

// Get the selected salesperson from the fill-in field
const selectedSalesPerson = “%filltext:name=SalesPerson%”;

// Function to get contact information based on the selected salesperson
function getContactInfo(salesPerson) {
return contactInfo[salesPerson] || { phone: “N/A”, email: “N/A” };
}

const info = getContactInfo(selectedSalesPerson);

// Output the contact information
"Phone: " + info.phone + "\nEmail: " + info.email;
%end

I really would like to get this to work as it will make sending information via email so much easier. The list would be expanded to include all sales people. It lists the dropdown and lets me choose but the script is not hidden and the contact info is never displayed. I am not the greatest with JavaScript but heard thats the preferred script for TextExpander.

Thanks,

Mike

Hey Mike, are you setting the Content Type to JavaScript instead of Rich Text?

I have tried both ways. Rich Text and JavaScript.

Hey Mike, @jeff got it working. Subscribe the Community Snippets Public Group and look at com.contactinfo.

2 Likes

That’s Awesome. I appreciate the help. I am going to expand this to cover many different sales teams. This will help out so much.

Mike G.

2 Likes