RE: CRMScript - using Macro-trigger: how to make a trigger on change of field OrgNr
Hi Edith,
Macros are a bit limited, so I don't think you can do it this way (although there might be a work around I'm not thinking of right now).
If you have access to do it with CRMScript, here's how you could do it.
#setLanguageLevel 3;
EventData ed = getEventData();
// Current ID of the contact
String contactId = ed.getInputValue("ContactEntity.ContactId");
// New Org.Nr of the contact
String contactOrgNr = ed.getInputValue("ContactEntity.OrgNr").substitute(" ", "").stripLeadingAndTrailing(" ");
String originalOrgNr;
// Gets the org.nr before save
SearchEngine seContact;
seContact.addField("contact.orgNr");
seContact.addCriteria("contact.contact_id", "Equals", contactId);
if(seContact.select() > 0)
originalOrgNr = seContact.getField(0);
if(originalOrgNr != contactOrgNr && !contactOrgNr.isEmpty())
{
// Email Values
String toEmailAddress = "to@email.com";
String subject = "subject";
String bodyHtml = "<p>Content</p>";
// To get a more dynamic solution, load a reply template and parse Customer related data
// Sends the email
Email e;
e.setValue("to", toEmailAddress);
e.setValue("subject", subject);
e.setValue("bodyHtml", bodyHtml);
e.send();
}