FindAppointment Restriction on Date (not time component)

Hi,

I want to be able to use FindAppointment to achive the following in Sql:

select * from crm7.APPOINTMENT where CAST(activeDate AS DATE) in ('2019-10-24','2019-10-26','2019-10-28')

 

Please can you advise how this, I have done the following, but this seems the incorrect method:

 

String[] AppontmentDaysToLoad = new String[] {"2019-10-24","2019-10-26","2019-10-28"};

ArchiveRestrictionInfo[] restrictions = new ArchiveRestrictionInfo[AppontmentDaysToLoad.Count * 2];

int pos=0;

foreach (String date in AppontmentDaysToLoad)
{
restrictions[pos] = new ArchiveRestrictionInfo()
{
Name = "date",
Operator = "after",
Values = new string[] { DateTime.Parse(date).AddDays(-1).ToString("yyyy.MM.dd") },
IsActive = true,
InterOperator = SuperOffice.Data.InterRestrictionOperator.And
};
pos++;

restrictions[pos] = new ArchiveRestrictionInfo()
{
Name = "endDate",
Operator = "before",
Values = new string[] { DateTime.Parse(date).AddDays(1).ToString("yyyy.MM.dd") },
InterOperator = SuperOffice.Data.InterRestrictionOperator.Or
};
pos++;
}

 

Cheers

Rich

 

RE: FindAppointment Restriction on Date (not time component)

Hi Rich,

I think what you want is to get all appointments on those three dates. If that is true, then the interoperator must be an Or, to say get me all appointments on this day, or this day, or this day.

Take note of the available operators for column datatypes to avoid the before/after logic - just use date.

To do that, you could use this code:

string[] AppontmentDaysToLoad = new string[] { "2019-10-24", "2019-10-26", "2019-10-28" };
List<ArchiveRestrictionInfo> restrictions = new List<ArchiveRestrictionInfo>();

foreach (var dateItem in AppontmentDaysToLoad)
{
    restrictions.Add(new ArchiveRestrictionInfo() {
        Name = "date",
        Operator = "date",
        Values = new string[] { dateItem },
        IsActive = true,
        InterOperator = SuperOffice.Data.InterRestrictionOperator.Or
    });
}

using (FindAgent fa = new FindAgent())
{
    var results = fa.FindFromRestrictions(restrictions.ToArray(), "Appointment", int.MaxValue, 0);

    // processes accordingly ...
}

Hope this helps!

Av: Tony Yates 23. okt 2019

RE: FindAppointment Restriction on Date (not time component)

Tony,

Many thanks for this, I was missing the operator 'date' which had stumped me.

Thanks for the link as well; I was going to ask if this info was avaliable!

Cheers

Rich

 

Av: Rich Hacker 25. okt 2019