Dynamics CRM wait condition timeout convert to utc time - dynamics-crm

I'm using workflow wait condition to update field in Entity. I have datetime field and when actual time is 2 days before this field value ,I want update another field in this entity. In CRM settings time zone is +1 UTC. So, this workflow wait condition works okay, only if I choose 2 days and 1 hour, but not just 2 days. How can I fix this?

You could write a custom workflow action that takes the number of days as an input parameter, calculates the adjusted wait period (ex: 2 days and 1 hour becomes 2 days), and then sets the result as an output parameters for use in the workflow's wait condition.

Related

Dynamics CRM workflow - prevent contemporary wait conditions on the same record

We have a wait condition of 5 days on a background workflow. If the workflow is triggered again on the same record before the 5 days period expires, we would like to stop the first wait condition, and only consider the new one. Is it possible, and how?
I solved by adding a "workflow execution counter" field to the entity, and modifying the workflow depending on the value of this field.

MSCRM OlderThanXHours and the current time

I created a QueryExpression with one of the Conditions set to ("dev_lastremarketingtime", ConditionOperator.OlderThanXHours, 1); 
The intent is the retrieve multiple records that are an hour after the value of dev_lastremarketingtime.
There are records in the table that meet this criterion, however, they are not returned. When I examine the record (RetrieveMultiple of a specific record this time) it seems that the times used for comparison are not consistent. 
For example, when viewing the account record in question, the dev_lastremarketingtime's value as shown on the account form is 5/17/2017 8:57 PM. the internal is time 5/18/2017 12:57:27 AM.  The wall clock at the time of the test shows 5/17/2017 10:38:11 PM (or 5/18/2017 2:38:11 AM UTC). This record should have been returned by the query (the current time is more than one hour after the value of dev_lastremarketingtime)
If I wait a few hours and run my app again, the expected records are retrieved.
It seems, therefore, that the Query expression with the ConditionOperator.OlderThanXHours is comparing the current Eastern Daylight time with the record's UTC time. 
How can I get this query to compare the same time zones (I don't think it matters which one)?
(My Personal options include the setting for Eastern Time
Instead of using the OlderThanXHours operator, maybe try using "less than", which provides control of the DateTime value to filter on.
This way you can use the UTC time minus an hour, like this:
var qe = new QueryExpression("myentity");
qe.Criteria.AddCondition("dev_lastremarketingtime", ConditionOperator.LessThan, DateTime.UtcNow.AddHours(-1));

Can I generate the number of business days in a month in Visual Studio?

I have a report that takes sales data from a few tables. I want to add a field that will divide the total sales for the given month by the total number of business days in that same month. Is there a way I can calculate that in an expression? Do I need to create a new table in the database specifically for months and their number of business days? How should I go about this?
Thank you
Intuitively, I would say that you need a simple function and a table.
The table is to host the exceptions like Independence day, labor day, etc.
The function will get two parameters: Month and Year (I'm not providing any sample code since you haven't specified which language you are using).
It will then build a date as yyyy-mm-01 (meaning, first day of the month). If will then loop from 2 to 31 and:
Create a new date by adding the index of the loop to the initial date,
Check if the resulting date is still within the month,
Check if it is a working or not working day (e.g. Sunday),
Check if it is found within the table of exceptions.
If the created date passes all the above tests, you add 1 to the counter.
Though it might look complex, it is not and it will provide you the correct answer regardless of the month (e.g. Feb.) and the year (leap or not).

user must login with in entered time interval

I have to restrict user login to my application based on the start time( just hour value) and end time(just hour value) they entered. I am storing those values in 1 ... 24 hour format. The query I'm running is.
select * from table WHERE startHour <= '10' and endHour >= '10'
(10 is current hour). This is not working if user enters end time and start time as 1. Can you guys help me the current way I need to work.
I have some questions. Are the start time and end time only in hours? Also, is it valid if the start time and end time are given the same values? That would mean that the user has to log in at the exact hour inputted and no leeway for minutes past or minutes before. Can you post the structure of your table containing the start time and end time entries?
Also, when you say it's not working, can you give the scenario of what occurs by then? Provide any exact error or issue.

How can I dynamically set the time period on a Workflow Time Trigger?

I have a custom object with Start and End date fields, and also a Status field.
When a new record is created, if the Start date specified is in the future, I would like to be able to have a Workflow update the Status field to 'Active' when the Start date is today. However, I only appear to be able to select a fixed number of days after which my Field Update task can be triggered. What I want is to set that number of days equal to Start date - Today's date.
Can this be done?
OK, I realised I can set the time delay to zero days after the Start date. Not intuitive (For me), but it makes sense.

Resources