When is a CRM tracing token not a tracking token?
Yet another fun instance of CRM doing strange things.
Ok. I need to create an email (no problem, done it in a workflow, and a scheduled task).
Then I need to "Send" it (not really sent, just marked as sent, I'm actually using it to record an SMS)
No problem, works in the scheduled task I've already done.
Started on the workflow and I get:
System.Web.Services.Protocols.SoapException: Server was unable to
process request. --->
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
Unexpected type for the property.
Schema error: property trackingtokenid does not have the expected type.
Well, that doesn't make sense. In both cases I was setting trackingtoken = "" Which is supposed to tell CRM to assign one for you. By the way, don't leave it = NULL, that crashes.
After much hunting I managed to track this back to the real cause.
The scheduled task was running as ME, and I'm a CRM user, no problem.
The workflow runs as Network Service. Not a CRM user, but a member of "PrivUserGroup" in the AD.
What does that mean?
What it means is that if you set CallerID.CallerGuidValue to a systemuserid guid, it is allowed to impersonate that user.
No set the ID, no valid user. This really should have been an authentication error.
By the way, if you set the caller ID every time, the situation reverses, the workflow runs, and the scheduled task bombs out with a security error. Like what we should have had.
So, the solution is to set the caller ID, and to set the scheduled tasks to run as a custom user with membership in PrivUserGroup. Of course that opens a whole set of other issues which we don't want to go into here.
Now, why?
Because of the tracking token format.
- Standard Prefix
- Location ID
- User ID
- Unique ID
Note the user ID? No CRM user = no CRM user ID, hence no valid tracking token.
Web Service call from the log
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
http://schemas.microsoft.com/crm/2006/WebServices">
xmlns="http://schemas.microsoft.com/crm/2006/CoreTypes">00000000-0000-00
00-0000-000000000000
xmlns="http://schemas.microsoft.com/crm/2006/WebServices">
1534e1d4-29a0-db11-bac3-000c29f05e38
false