![](https://www.infallibletechie.com/wp-content/uploads/2024/04/Auto-populate-Pre-Chat-Form-Fields-in-Salesforce-Messaging-for-In-App-and-Web-1024x576.jpg)
embeddedservice_bootstrap.prechatAPI.setVisiblePrechatFields() can be used to auto populate Pre-Chat Form Fields in Salesforce Messaging for In-App and Web.
Sample Code:
window.addEventListener("onEmbeddedMessagingReady", e => {
embeddedservice_bootstrap.prechatAPI.setVisiblePrechatFields({
"_firstName": {
"value": "Test",
"isEditableByEndUser": false
},
"_lastName": {
"value": "User",
"isEditableByEndUser": false
},
"_email": {
"value": "[email protected]",
"isEditableByEndUser": false
},
"_subject": {
"value": "Testing",
"isEditableByEndUser": true
}
});
});
Use the above code before the embeddedservice_bootstrap.init() method.
![](https://www.infallibletechie.com/wp-content/uploads/2024/04/Salesforce-Messaging-for-In-App-and-Web-Pre-Chat-Population-1024x813.png)
isEditableByEndUser indicate wheter the Pre-Chat field can be updated by the Visitor or not.
Output:
![](https://www.infallibletechie.com/wp-content/uploads/2024/04/Salesforce-Messaging-Pre-Chat-Populate-Automatically-568x1024.png)