Hi Spiker,
As we know, system will generate a "Marketing email test send" entity record in each time we send a marketing email.
However, "Subject" you added is only the name of "Marketing email test send" entity instead of the subject field of Marketing email entity itself.
The subject of test send email is from subject of marketing email, thus the only way to achieve your requirement would be by changing subject of marketing email when we editing quick create form.
Please take my steps as reference:
1. Create a JScript web resource then add code below to the file:
var addPrefix = function (executionContext) {
var formContext = executionContext.getFormContext();
formContext.getAttribute("msdyncrm_subject").setValue("Test_");
}
var changeParentEmailSub = function (executionContext) {
var formContext = executionContext.getFormContext();
var testSubject = formContext.getAttribute("msdyncrm_subject").getValue();
var id = getParameterByName("id", parent.location.href);
var etn = getParameterByName("etn", parent.location.href);
var data = {
msdyncrm_subject: testSubject
}
Xrm.WebApi.updateRecord(etn, id, data).then(
function success(result) {
console.log(result);
},
function (error) {
console.log(error.message);
}
);
}
var getParameterByName = function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' name '(=([^]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\ /g, ' '));
}
There are 3 functions:
addPrefix: populate the subject field with prefix.
changeParentEmailSub: update subject of marketing email to subject of "Marketing email test send" when we lose focus on the subject field.
(Why the function will be executed at subject OnChange event?
Because system will send marketing email immediately after we clicked "save" button before subject of marketing email get update by custom code.
Thus we update the field at subject OnChange event to give enough time to make sure subject of marketing email can get update.)
getParameterByName: get guid and entity name of parent marketing email in URL
2. Add addPrefix function to OnLoad event of form.
After enabled the function, also remember to check "Pass execution context.." option.(It is required for second function.)
3. Add changeParentEmailSub function to OnChange event of Subject field.
Result:
Now the subject is added with prefix, we should change subject of marketing email back when it comes to formal campaign.
(Or you could create a marketing email record for only test purpose.)
Regards,
Clofly