Question Status

Verified
martijnburger asked a question on 14 Jan 2014 2:07 PM

I am trying the code below, however it always returns 0 records in the EntityCollection, while documentlocation records are set regarding the account id I provide to the function. I am in doubt if I can put the Guid id in the Values of the ConditionExpression. I've tried id.ToString() also, but also no result.

internal static EntityCollection GetSPDocumentLocation(IOrganizationService service, Guid id)

{

   SharePointDocumentLocation spd = new SharePointDocumentLocation();

   QueryExpression query = new QueryExpression

   {

       EntityName = "sharepointdocumentlocation",

       ColumnSet = new ColumnSet("sharepointdocumentlocationid"),

       Criteria = new FilterExpression

       {

           Conditions =

           {

               new ConditionExpression

               {

                   AttributeName = "regardingobjectid",

                   Operator = ConditionOperator.Equal,

                   Values = { id }

               }

           }

       }

   };

   return service.RetrieveMultiple(query);

}

Reply
Verified Answer
Vijay Waghmare responded on 15 Jan 2014 9:11 AM

I wasn't aware that this was delete case, as you are suspecting you can try pre-validation stage if not already tried, that executes out of transaction.

Also you can try approach of having SQL query on filtered view.

Reply
Ben Hosking responded on 14 Jan 2014 2:18 PM

Have you got this query to work in an advanced find.

You can download the fetchXml this would show you what fields and values were being passed.

In fact you could try creating the query as a fetchXml in the plugin

crmbusiness.wordpress.com/.../build-queries-with-fetchxml-instead-of-queryexpression

Ben  Hosking

If the my post helped you please mark my post as the suggested answer

Hosk's Dynamic CRM Blog   |  @BenHosk |  Rockstar365

Hosks CRM Dev YouTube Channel

Reply
martijnburger responded on 15 Jan 2014 4:20 AM

Tried that already. Same problem.

Reply
Vijay Waghmare responded on 15 Jan 2014 8:12 AM

Refer below URL for help,

msdn.microsoft.com/.../gg309548.aspx

Thanks,

Vijay Waghmare

Reply
martijnburger responded on 15 Jan 2014 8:19 AM

Really? You suggest that as an answer? I am not posting a problem on this forum before I do a simple google search and try out various scenario's. For now, debugging some more this lead me to this result: I have 3 accounts with a documentlocation record associated. Let's say account GUID's: ACC1, ACC2 and ACC3. If I provide the GUID ACC1, the entitycollection that is returned without the conditionoperator is three accounts, with GUID's ACC2, ACC3 and an unknown GUID. If I provide the GUID ACC2, the entitycollection that is returned has GUID's ACC1, ACC3 and the same unkown GUID.

The function is called from a plugin Delete PreOperation event. Maybe the system returns some entity reference id when it is in the transaction?

Reply
Verified Answer
Vijay Waghmare responded on 15 Jan 2014 9:11 AM

I wasn't aware that this was delete case, as you are suspecting you can try pre-validation stage if not already tried, that executes out of transaction.

Also you can try approach of having SQL query on filtered view.

Reply
martijnburger responded on 15 Jan 2014 11:40 AM

Okay. That was unexpected. Registering the plugin Pre Validation works! It seems that even when registering an event PRE Operation the related records (cascading delete is set on the relation) are already deleted. Can someone confirm that???

Reply
Vijay Waghmare responded on 15 Jan 2014 9:23 PM

For me it’s an issue of data row locked out at SQL level, as plugin was trying to read a record which is being submitted for deletion (cascade). Once committing changes it actually delete record from database when transaction is successful.

As you are aware pre operation run “in transaction” mode; hence plugin was not able to retrieve expected records due to record lock out.

Changing stage to pre-validation, which runs out of transaction mode and able to retrieve all expected result in response.

Hope this help you to clear understanding.

Requesting you to provide enough details of issue to avoid any confusion while suggesting answer :)

Thanks,

Vijay Waghmare

Reply