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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create and Update Views for entity Programatically

(0) ShareShare
ReportReport
Posted on by 15

Hi Experts ,

I would like to create new view using odata query.I have a xml file which contain the fetchxml and layout xml for entity.

var entity = {};
entity.fetchxml = "<fetch version='1.0' mapping='logical'> <entity name='webresource'> <attribute name='name' /> <attribute name='displayname' /> <attribute name='description' /> <attribute name='webresourceid' /> <attribute name='webresourcetype' /> <attribute name='iscustomizable' /> <filter type='or'> <condition attribute='webresourcetype' operator='eq' value='5' /> <condition attribute='webresourcetype' operator='eq' value='6' /> <condition attribute='webresourcetype' operator='eq' value='7' /> <condition attribute='webresourcetype' operator='eq' value='10' /> </filter> <filter type='and'> <condition attribute='ishidden' operator='ne' value='1' /> </filter> <order attribute='displayname' descending='false' /> </entity> </fetch>";
entity.layoutxml = "<grid name='resultset' object='9333' jump='displayname' select='1' preview='0' icon='1'> <row name='result' id='webresourceid'> <cell name='name' width='200' /> <cell name='displayname' width='100' /> <cell name='description' width='250' /> <cell name='webresourcetype' width='100' /> <cell name='webresourceid' ishidden='1' width='100' /> </row> </grid>";
entity.returnedtypecode = 'webresource';
entity.querytype = 64;
entity.name = "test";

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/savedqueries", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));

I want to create a view for Webresource entity but  layout and fetch xml casue internal server error when i run same code for opportunity it runs by reffering this 

https://community.dynamics.com/crm/f/117/t/158168

...........................................................................................................


<grid name='resultset' object='9333' jump='displayname' select='1' preview='0' icon='1'>
<row name='result' id='webresourceid'>
<cell name='name' width='200' />
<cell name='displayname' width='100' />
<cell name='description' width='250' />
<cell name='webresourcetype' width='100' />
<cell name='webresourceid' ishidden='1' width='100' />
</row>
</grid>

<fetch version='1.0' mapping='logical'>
<entity name='webresource'>
<attribute name='name' />
<attribute name='displayname' />
<attribute name='description' />
<attribute name='webresourceid' />
<attribute name='webresourcetype' />
<attribute name='iscustomizable' />
<filter type='or'>
<condition attribute='webresourcetype' operator='eq' value='5' />
<condition attribute='webresourcetype' operator='eq' value='6' />
<condition attribute='webresourcetype' operator='eq' value='7' />
<condition attribute='webresourcetype' operator='eq' value='10' />
</filter>
<filter type='and'>
<condition attribute='ishidden' operator='ne' value='1' />
</filter>
<order attribute='displayname' descending='false' />
</entity>
</fetch>

kindly help me

*This post is locked for comments

I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans