Sometimes the OOB view deleted mistakenly and it create problems.
The same scenario come with me, I have custom entity Bid and its associated view deleted mistakenly and we need to create one to many relationship with same Bid entity.
But the associated view of custom entity bid is deleted so we can't create relationship.
Through following code i created the associated view of Bid entity and then i create one to many relationship with same bid entity.
// Create the view.
The same scenario come with me, I have custom entity Bid and its associated view deleted mistakenly and we need to create one to many relationship with same Bid entity.
But the associated view of custom entity bid is deleted so we can't create relationship.
Through following code i created the associated view of Bid entity and then i create one to many relationship with same bid entity.
// Create the view.
System.String layoutXml =@"<grid name='resultset' object='3' jump='ab_name' select='1'
preview='1' icon='1'>
<row name='result' id='ab_bidid'>
<cell name='ab_name' width='150' />
</row>
</grid>";
preview='1' icon='1'>
<row name='result' id='ab_bidid'>
<cell name='ab_name' width='150' />
</row>
</grid>";
System.String fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='ab_bid'>
<attribute name='ab_name' />
<attribute name='ab_bidid' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='0' />
</filter>
<order attribute='ab_name' descending='false' />
</entity>
</fetch>";
<attribute name='ab_name' />
<attribute name='ab_bidid' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='0' />
</filter>
<order attribute='ab_name' descending='false' />
</entity>
</fetch>";
Entity entity = new Entity("savedquery");
entity["description"] = "Bid Associated View";
entity["name"] = "Bid Associated View";
entity["querytype"] = 2; // 2 is type code of Associated view
entity["returnedtypecode"] = "ab_bid"; // enity name
entity["fetchxml"] = fetchXml;
entity["description"] = "Bid Associated View";
entity["name"] = "Bid Associated View";
entity["querytype"] = 2; // 2 is type code of Associated view
entity["returnedtypecode"] = "ab_bid"; // enity name
entity["fetchxml"] = fetchXml;
entity["layoutxml"] = layoutXml;
Guid _customViewId = service.Create(entity);
Guid _customViewId = service.Create(entity);