Triggers for "Before saving company" and "After saving company" - Original values and UpdatedBy

lock
push_pin
done
Answered
4

I'm trying to make a script where the administration of the company gets an email of important changes on the company card. The logic behind it is finished, but im struggling with the different attributes of the triggers "Before saving company" and "After saving company".

In "Before saving company", the :org value of a User Defined Field is showed as the previously set value, and the normal value is the new value that it has been changed to. See below:
ContactEntity.CustomFields.SuperOffice:23 = [I:39]
ContactEntity.CustomFields.SuperOffice:23:org = [I:41]

And in "After saving company", the :org value will always be identical to the new value set. 
ContactEntity.CustomFields.SuperOffice:23 = [I:39]
ContactEntity.CustomFields.SuperOffice:23:org = [I:39]

However, when using "Before saving company", the field "ContactEntity.UpdatedBy.X" will be linked to the last person that made changes to the company, not the person who is changing the company now.

I need the trigger to tell me the changes made, and who made these changes, but it seems i have to get this information from 2 different triggers.

Here is the script for extracting all the EventData from the triggers, both the TriggerScript for Before and After saving company are logically identical:

#setLanguageLevel 4;

EventData ed = getEventData();
Map fields = ed.getInputValues();
String text;

fields.first();
while (!fields.eof()){
  text.append(fields.getKey() + " = " + fields.getVal() + "<br>");
  fields.next();
}

Email e;
e.setValue("envelopeFrom", "hidden");
e.setValue("from", "hidden");

e.setValue("to","hidden");

e.setValue("subject", "Endringer på firmakort | FØR");
e.setValue("bodyHtml", text);
e.setValue("body",htmlConvToText(text));
e.send();

18 Mar 2025 | 01:59 PM

All Replies (4)

Hi Frederic

You could pass the ":org" value using ed.setStateValue() in the "before saving" trigger. This passes it to the "after saving" trigger, where you can pick it up with ed.getStateValue(). Then you can execute the rest of your logic there.

Espen

18 Mar 2025 | 02:24 PM
Worked very well Espen, thanks 😊
18 Mar 2025 | 06:24 PM

Alternatively, use the getActiveUser global method to get the associate id of the user making the change in the before save trigger

18 Mar 2025 | 08:03 PM

Would also like to see changes of the category of the Company. In the example below i changed from "Eksisterende kunde" --> "Potensiell kunde", and it only seems like the value of the Tooltip stays on the old value in the "Before trigger" script.

Before Trigger:
ContactEntity.Category.Id --> 2
ContactEntity.Category.Tooltip --> Alle eksisterende kunder skal vises her.
ContactEntity.Category.Value --> Potensiell kunde

After Trigger:
ContactEntity.Category.Id --> 2
ContactEntity.Category.Tooltip -->
ContactEntity.Category.Value --> Potensiell kunde

21 Mar 2025 | 12:28 PM

Add reply