web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to retreive documentlocation records for an account or contact?

(0) ShareShare
ReportReport
Posted on by 250

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);

}

*This post is locked for comments

I have the same question (0)
  • Hosk Profile Picture
    on at

    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

  • martijnburger Profile Picture
    250 on at

    Tried that already. Same problem.

  • Vijay Waghmare Profile Picture
    on at

    Refer below URL for help,

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

    Thanks,

    Vijay Waghmare

  • martijnburger Profile Picture
    250 on at

    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?

  • Verified answer
    Vijay Waghmare Profile Picture
    on at

    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.

  • martijnburger Profile Picture
    250 on at

    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???

  • Vijay Waghmare Profile Picture
    on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans