Beispiel #1
0
        public static async Task GetAccountCounts(CRMWebAPI api, ITurnContext <IMessageActivity> context)
        {
            await Task.Run(async() =>
            {
                dynamic whoamiResults = await api.ExecuteFunction("WhoAmI");
                var opt = new CRMGetListOptions
                {
                    Top    = 5000,
                    Filter = "_createdby_value eq " + whoamiResults.UserId + " or _modifiedby_value eq " + whoamiResults.UserId
                };
                var count = await api.GetList("accounts", QueryOptions: opt);
                if (count == null)
                {
                    count      = new Xrm.Tools.WebAPI.Results.CRMGetListResult <ExpandoObject>();
                    count.List = new List <ExpandoObject>();
                }
                else if (count.List == null)
                {
                    count.List = new List <ExpandoObject>();
                }

                var card = new HeroCard();

                var action = new CardAction()
                {
                    Type  = ActionTypes.MessageBack,
                    Title = $"Accounts owned by me: {count.List.Count}",
                    Value = count.ToString()
                };
                card.Buttons = new List <CardAction>();
                card.Buttons.Add(action);
                await DisplayMessage(card, context);
            });
        }
        static void Main(string[] args)
        {
            var response = GetAPI();

            response.Wait();

            CRMWebAPI api = response.Result;

            Task.Run(async() =>
            {
                Xrm.Tools.WebAPI.Results.CRMGetListResult <System.Dynamic.ExpandoObject> results = await GetAccounts(api);
                dynamic result = results.List[0];
                Console.WriteLine($"Name: {result.name}\nID: {result.accountid}");
            }).Wait();
        }