Not sure of the title explains the topic much. So let me illustrate with an example on what we were trying to achieve for our customer.
The customer had a requirement where the users would need to enter weekly data and the report would be locked for the week by Thursday 5 PM PST time of every week. Our servers were located in PST Time zone. If you really ask me, when I first got this requirement, I really didn’t pay any heed to this as I though this would be pretty simple stuff.
So let’s see how this small stuff gave me some sincere and serious thinking. Let decide on how to approach a feasible solution for this. Considering that our customers had this report being accessed by users all round the world, the following are the options we had.
- Determine the PST time using getTimeZoneOffset method.
- Using actions.
Let us evaluate each option in specific order
Determining the PST Time using getTimezoneOffset method:
$date = new Date(); // convert to msec // subtract local time zone offset // get UTC time in msec $utc = $date.getTime() – ($date.getTimezoneOffset() * 60000); $pstdate = new Date($utc + (3600000*’-8’));
All so fine this far. So what’s the problem if we use this. Well getTimezoneOffset does not take into effect the DST (Daylight saving’s time). So we had to write code to include the day light saving based on the month from which the daylight savings would start and then adjust the time accordingly. We discussed this with our customer and they did not want us to go that route.
So actions was our next big bet. We will create an action with output parameter of type datetime and then assign the output parameter to the ‘Process Execution Time’. All set we thought. But CRM still had few surprises up its sleeve.
So now what? Finally I came up with the below idea.
- Create an action
- Set an output parameter of a the action of type ‘String’. Just notice I have mentioned String and not datetime. I will come back to this.
- Create a custom workflow activity with a output parameter of type string to hold the current server time.
- Set the output parameter in the custom workflow activity with the string representation of the server time
The final step is to set the output parameter of the action with the value of the output parameter of the action
And finally I was able to achieve this. Seems like a mountain solution to a molehill requirement isn’t it.
Sharing this in case someone finds this useful.
Hope this helps!