Currently I have a map that looks like this to send emails via an API:
Map body = {"personalizations": [
{
"to": [
{
"email": "$receiverEmail"
}
],
"dynamic_template_data": {
"EmployeeName": "$employeeName",
"EmployeeID": "$employeeID",
"PatientName": "$patientName",
"ProviderName": "$providerName",
"TreatmentDate": "$treatmentDate",
"Diagnosis": "$diagnosis"
}
}
],
"from": {
"email": "$userEmail"
},
"template_id": "$templateID"
};
I am planning to use this structure with 2 forms of emails and for that to happen I need to update/add values under the dynamic_template_data key.
Therefore I am trying to find out how I could update/add value to that specific key. I found a function called Map.update() but I am unsure as how to properly use it. How do I approach this problem?
Just assign a new value to a specific key to update.
body['personalizations'][0]['dynamic_template_data']['EmployeeName'] = 'John Doe';
or
body['personalizations'][0]['dynamic_template_data']['Salary'] = 5000.00;
another example to do an assignment only if it doesn't exist yet
(body['personalizations'][0] as Map).putIfAbsent('Salary', () => 5000.00);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With