문제

I encountered some strange behavior while working with a plugin for MSCRM 2011.
The code below is part of a plugin registered on the create & update action on the product entity. Each product has a couple of tasks (defined as an activity entity) related to it and I want the open tasks of the product as a result.

var tasks = from t
            in orgContext.CreateQuery("fvm_producttask") 
            where (t.GetAttributeValue<int>("statuscode") != 2 && t.GetAttributeValue<int>("statuscode") != 3)
            where t.GetAttributeValue<EntityReference>("fvm_regardingproduct").Id == product.Id
            select t;

String xx = "";
foreach (String x in tasks.First().Attributes.Keys) {
    xx += x + "\r\n";
}

throw new InvalidPluginExecutionException(xx);  

When I execute the code above as a CRM plugin I get only 2 keys in my result (subject, activityid), when i remove the second where clause I get the desired result of all keys from the producttask entity.

Anyone knows the reason for this behavior? I know I can solve this by filtering out all the tasks for other products out afterwards but this is only a (dirty) workaround. I'd like to know why the code above won't work.

Below you can check out the record I want to retrieve.

OwnerId                         FA7AF161-D666-E111-8537-001E4F1285B0 
OwningUser                      FA7AF161-D666-E111-8537-001E4F1285B0
OwningTeam                      NULL
OwningBusinessUnit              168D9521-434E-E111-99C9-001E4F1285B0
ActualEnd                       NULL
VersionNumber                   0x00000000002D40BD
ActivityId                      655E63A1-84B9-E311-A79F-005056A56527
IsBilled                        0
CreatedBy                       FA7AF161-D666-E111-8537-001E4F1285B0
Description                     Product Dimensions Required
ModifiedOn                      2014-04-01 14:07:11.000
ServiceId                       NULL
ActivityTypeCode                10134
StateCode                       0
ScheduledEnd                    2014-04-04 10:01:45.000
ScheduledDurationMinutes        4320        
ActualDurationMinutes           NULL
StatusCode                      1
ActualStart                     NULL
CreatedOn                       2014-04-01 10:01:45.000
PriorityCode                    1
RegardingObjectId               NULL
Subject                         Product Requires Attention
IsWorkflowCreated               0
ScheduledStart                  2014-04-01 10:01:45.000
ModifiedBy                      FA7AF161-D666-E111-8537-001E4F1285B0
TimeZoneRuleVersionNumber       0
UTCConversionTimeZoneCode       NULL
InstanceTypeCode                0
SeriesId                        NULL
IsRegularActivity               1
ModifiedOnBehalfBy              FA7AF161-D666-E111-8537-001E4F1285B0
CreatedOnBehalfBy               NULL
TransactionCurrencyId           NULL
ExchangeRate                    NULL
LeftVoiceMail                   0
IsMapiPrivate                   0
RegardingObjectTypeCode         NULL
RegardingObjectIdName           NULL 
ImportSequenceNumber            NULL
OverriddenCreatedOn             NULL
fvm_RegardingProduct            207592F0-E9B8-E311-A79F-005056A56527
fvm_Category                    1 
도움이 되었습니까?

해결책

Might be that the entity you are referencing has locked fields.

Do you do any operations earlier in the program flow?

Maybe try to Dispose() the context before the CreateQuery.. (or, if relevant, wrap the preceding context initialization in a using block )

HTH Bob

다른 팁

When working with the CRM SDK, it will only return attributes that have a value for them. I'm guessing your first task has all values null except for the Subject and ActivityId.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top