Skip to main content

Yogen Trikannad
Yogen Trikannad
26

Do you have questions for Yogen Trikannad?

Log in to ask Yogen Trikannad questions publicly or anonymously.

Post
Hello Sir


This is the code for Web API retrieving data
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">;
<head>
<meta charset="utf-8" />
<title></title>
<script src="new_GlobalHelper"></script>
<script src="new_/Scripts/Somefile"></script>
<script>
function Buttonclick() {



// var contact =
//{
// "firstname": "Sample Contact",
// "lastname": "Web API",

//}

// create account record
//parent.Xrm.WebApi.createRecord("contact",contact).then(
// function success(result) {
// document.getElementById("text").innerHTML = result.id;
// // perform operations on record creation
// },
// function (error) {
// document.getElementById("text").innerHTML = error.message;
// // handle error conditions
// }
//);
// Use retrieve multiple for retrieving multiple records
parent.Xrm.WebApi.retrieveMultipleRecords("contact","$select=firstname,lastname,address1_city&$filter=address1_city eq 'Redmond'", 5000).then(
function success(result) {
var text;
for (var i = 0; i < result.entities.length; i++) {
console.log(result.entities[i]);
text += result.entities[i].firstname
}
// perform additional operations on retrieved records
document.getElementById("text").innerHTML = text;
},
function (error) {
console.log(error.message);
// handle error conditions
}
);



//Accessing from elements from HTML web resource
// We have to follow old code "Xrm.Page" not new code "formContext"
//var accountName = parent.Xrm.Page.getAttribute("name").getValue();

// In HTML web resource , you can use DOM(Document Object Model)
// In JavaScript web resource , DOM is not supported
// document.getElementById("text").innerHTML = accountName
}



</script>


</head>
<body>
<input type="button" value="Click Me" onclick="Buttonclick()" />
<p id="text">

</p>
</body>
</html>

On click Me button there is no response coming

Post
Grouping and Aggregation Issue - Section 5 Aggregate Operations using FetchXML
Hello Sir I am getting below runtime error while using average method .

System.ServiceModel.FaultException`1: 'Aggregate AVG or SUM is not supported for attribute of type primarykey.'


The screenshot is attached



Code:-

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Tooling.Connector;

using Microsoft.Xrm.Sdk.Query;





namespace ConsoleApp

{

class Program

{

static void Main(string[] args)

{

// Authenicate

string connectionString = "AuthType=Office365;Url=https://mvcmar2017.crm8.dynamics.com/ ;Username=mvcmar2017@mvcmar2017.onmicrosoft.com;Password=Kenya@2020";

CrmServiceClient service = new CrmServiceClient(connectionString);



// Counting Leads



string query = @" <fetch distinct='false' mapping='logical' aggregate='true'>

<entity name='lead'>

<attribute name='leadid' alias='NumberofLeads' aggregate='avg' />

</entity>

</fetch>";

EntityCollection collection = service.RetrieveMultiple(new FetchExpression(query));

foreach (Entity item in collection.Entities)

{

Console.WriteLine(((AliasedValue)item.Attributes["NumberofLeads"]).Value.ToString());



}

Console.Read();



// Fetch XML

/*

string query = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

<entity name = 'contact'>

<attribute name = 'fullname' />

<attribute name = 'parentcustomerid' />

<attribute name = 'telephone1' />

<attribute name = 'emailaddress1' />

<attribute name = 'contactid' />

<order attribute = 'fullname' descending = 'false' />

<filter type = 'and' >

<condition attribute = 'statecode' operator= 'eq' value = '0' />

<condition attribute = 'address1_city' operator= 'eq' value = 'Redmond' />

</filter >

</entity >

</fetch > ";

EntityCollection collection = service.RetrieveMultiple(new FetchExpression(query));

foreach (Entity contact in collection.Entities)

{

Console.WriteLine(contact.Attributes["fullname"].ToString());



}

Console.Read();

*/







}

}





}

I have uploaded the same query on Udemy.
No more items...