- Click the New trigger (script) in the trigger pane. In the search box, type Before saving company and click the trigger.
-
The Description field should contain a short description of what your trigger is doing, in this case, I’ll write Validate OrgNr.
- If you want this trigger to be enabled, remember to click the toggle box on the right side.
- In the textbox below, we can write whatever we want, although if you insert code that is not supported by CRMScript, it will give you an error message when clicking the OK button.
- The full code for preventing a save unless the organization number is filled out, could look something like this:
What if I don’t know the name of the input value I want to fetch?
My preferred way of finding out which fields I’ve got access to is by using the Trace function.- Save your script by clicking OK (Verify that you don’t get any error messages)
- In the button row above the script, click on the Trace script button.
- Verify that the Description field is not empty and the Enabled checkbox is checked, use the User filter if you want a user-specific trace, and click OK. Now you’ve activated tracing on the script that you’ve just created, and this enables you to go through the script step-by-step to see which variables you’ve got access to. For easy access, keep this tab open for now.
- In Sales (in a new tab), go to a company card, click Edit (), and then click Save so that the trigger will run the script.
-
Go back to the tab where you have the trace, and click Refresh. You should be able to find a new row in the trace of the trigger you’ve just created, click the row.
*On the left side, you’ve got the script, with a blue line displaying which row you’re tracing. The right side displays all available variables, with a … which you can click to expand.
- If you have the
EventData ed = getEventData();code you should be able to see aned …on the right side, and if you click this you should be able to seeinputValues …- expand this as well.
- If you have the
ContactEntity.OrgNr.
Click Return in the button row, and then click Trigger to go back to the script that you’ve started and click Edit.