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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

(0) ShareShare
ReportReport
Posted on by 894

Hi All

How to find Recent Views or Recent Record in CRM  using JavaScript or C# code(programmatically)

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at
    RE: How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

    Hi There,

    You can use both Javascript(Web Api) or Plugin(C#) to accomplish this task.

    You have to use the fetch XML in both of them and sort the record as descending.

    You can use below for retriving latest record:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" count="1">

    <entity name="account">

      <attribute name="name" />

      <attribute name="primarycontactid" />

      <attribute name="telephone1" />

      <attribute name="accountid" />

      <order attribute="createdon" descending="false" />

    </entity>

    </fetch>

    You can use http://msxrmtools.com/fetchxml to test your XML and see if you are getting desired result.

    www.inogic.com/.../execute-fetchxml-using-web-api-in-dynamics-crm-2016

    arunpotti.wordpress.com/.../retrieve-records-using-fetchxml-c-sdk-in-crm

    mark my suggestion as verified if this helps.

    cheers!

  • gdas Profile Picture
    50,091 Moderator on at
    RE: How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

    Hi ,

    For recent view records you may introduce one field in your entity and when the record will access  write a plugin  to update the date time of last access , similar way you can also set the last view id in another field when retrievemultiple get executed.

    Hope this helps.

  • CRM Develope Profile Picture
    894 on at
    RE: How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

    Thanks Rawish Kumar,Goutam Das

    I get list of record for below link...Working with programmatically

    www.magnetismsolutions.com/.../recently-viewed-records-and-views-in-microsoft-crm-2016

  • CRM Develope Profile Picture
    894 on at
    RE: How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

    Below Working code :-

               QueryExpression query = new QueryExpression

               {

                   EntityName = "userentityuisettings",

                   ColumnSet = new ColumnSet(true),

                   Criteria =

                   {

                       Filters =

           {

               new FilterExpression

               {

                   FilterOperator = LogicalOperator.And,

                   Conditions =

                   {

                       new ConditionExpression("owninguser",

                           ConditionOperator.Equal, myId),

                       new ConditionExpression("recentlyviewedxml",

                           ConditionOperator.NotNull)

                   }

               }

           }

                   }

               };

               DataCollection<Entity> result =

                   service.RetrieveMultiple(query).Entities;

               foreach (Entity entity in result)

               {

                   string rvXML = entity.Attributes["recentlyviewedxml"].ToString();

                   XElement xRVXML = XElement.Parse(rvXML);

                   string type = xRVXML.FirstAttribute.Value;

                   //if (type == "1030")

                   //{

                       IEnumerable<XElement> rvItems = from rvElem in

                                                           xRVXML.Descendants("RecentlyViewedItem")

                                                       select rvElem;

                       foreach (XElement rvItem in rvItems)

                       {

                           IEnumerable<XElement> pStatuses = from rviElem in

                                                                 rvItem.Descendants("PinStatus")

                                                             select rviElem;

                           foreach (XElement pinStatus in pStatuses)

                           {

                               pinStatus.Value = "true";

                           }

                       }

                       entity.Attributes["recentlyviewedxml"] = xRVXML.ToString();

                       //service.Update(entity);

                   //}

               }

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: How to find Recent Views or Recent Record in CRM By JavaScript or C# code(programmatically)

    Hi

    There are few ways you could do this, could you try the following Fetch Query on FetchXML Builder XrmToolBox plugin

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >

     <entity name="userentityuisettings" >

       <attribute name="objecttypecode" />

       <attribute name="recentlyviewedxml" />

       <filter type="and" >

         <condition attribute="recentlyviewedxml" operator="like" value="%type>1%" />

       </filter>

     </entity>

    </fetch>

    This should give the list of views that are viewed by each user. You can do grouping and counting as well. I would first start with the full list.

    The actual RecentlyViewedXML will look something like the following

    <RecentlyViewedEntityData etc="4202">

     <RecentlyViewedItem>

       <Type>1</Type> - Type 1 is View

       <ObjectId>{CC98CB1F-6552-4FD8-9E2F-39A1CAD2F710}</ObjectId>

       <EntityTypeCode>4202</EntityTypeCode>

       <DisplayName>Email</DisplayName>

       <Title>All Emails</Title>  View Name

       <Action>viewtype=1039&sitemappath=SFA%7cMyWork%7cnav_activities&type=email</Action>

       <IconPath></IconPath>

       <PinStatus>false</PinStatus>

       <ProcessInstanceId></ProcessInstanceId>

       <ProcessId></ProcessId>

       <LastAccessed>03/17/2019 16:48:29</LastAccessed>

     </RecentlyViewedItem>

    </RecentlyViewedEntityData>

    The above query is to get recently used views.  if the fetch work for you, you can convert the FETCH to query expression in FetchXML editor and use it in your c# code

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans