Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Calendar entity service.retrieve not returning the calendarrules attribute #528

Closed
durgaprasadkatari opened this issue Dec 4, 2020 · 5 comments

Comments

@durgaprasadkatari
Copy link
Contributor

I'm facing an issue with service.retrieve call on the calendar entity. Calendar is special type entity in MS CRM when we do the retrieve call it will automatically return the "calendarrules" entity collection attribute, but if we specify the "calendarrules" in the columnset it is throwing the error "attribute doesn't exist in the calendar entity".
To fix the unit test I have added the "calendarrules" attribute in the service.retrieve call but this is throwing the error in CRM. Please suggest a workaround to resolve this issue.
var holidaySchedule = service.Retrieve("calendar", serviceCalendarId, new ColumnSet("calendarid", "calendarrules"));

@BetimBeja @jordimontana82

@BetimBeja
Copy link
Contributor

Since the implementation of the IOrganizationService is based on Fakes you can Fake the result for your retrieve on this test, so that it returns the expected result:

  A.CallTo(() => service.Retrieve("calendar", A<Guid>._, A<ColumnSet>._)).Returns(new Entity("calendar") {Id=Guid.NewGuid() });

@jordimontana82
Copy link
Owner

Hi @durgaprasadkatari thanks for raising this.

Just wondering if you tried an advanced find that produces the same as that .Retrieve but with a FetchXml query that returns the calendar rules? If that's the case then you could query it that way for the time being.

Otherwise, feel free to try what @BetimBeja suggested . I might look into this as an enhancement for the next version.

@jordimontana82 jordimontana82 added this to the v2.x milestone Dec 8, 2020
@durgaprasadkatari
Copy link
Contributor Author

durgaprasadkatari commented Dec 9, 2020

Hi @jordimontana82
Calendar entity is not available in advance find, but I tried in Fetchxml builder it returns the calendar rules even if I don't specify the attribute in the fetchxml query. I had converted the service.retrieve into RetrieveRequest in the plugin and mocked the RetrieveRequest in my unit test case using this below code and this was solved my problem.

`context.AddExecutionMock<RetrieveRequest>(request =>
        {
            var req = request as RetrieveRequest;
            if (req.Target.LogicalName == "calendar")
            {
                Entity calendarEntity = lstEntities[4];
                var response = new RetrieveResponse()
                {
                    Results = new ParameterCollection { { "Entity", calendarEntity } }
                };
                return response;
            }
            return new RetrieveResponse();
        });`

But I also tried the @BetimBeja approach now and it is also solved my problem. I changed my plugin code back to service.retrieve().
Thanks!

@durgaprasadkatari
Copy link
Contributor Author

Do you want to close this issue?

@jordimontana82
Copy link
Owner

Yes, I'm closing it and moving the enhancement to a separate issue #532

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants