Creating a Contact View
- I am trying to create a view using the Microsoft.Crm.SdkTypeProxy.CrmService library. I have been successful in creating the view, however it does not show all the columns defined in the userquery.columnsetxml
The query.fetchxml = entitySchema.XmlFetchSchema looks like this:public void CreateContactView( string name ) { EntitySchema entitySchema = SchemaManager.GetEntitySchema( "myxmlfile.xml" ); userquery query = new userquery( ); query.name = name; query.columnsetxml = entitySchema.XmlColumnSetSchema; query.querytype = new CrmNumber( 0 ); query.returnedtypecode = EntityName.contact.ToString( ); query.fetchxml = entitySchema.XmlFetchSchema; TargetCreateUserQuery target = new TargetCreateUserQuery() { UserQuery = query }; CreateRequest request = new CreateRequest( ) { Target = target }; CreateResponse response = (CreateResponse)_service.Execute( request ); PublishXmlRequest publishRequest = new PublishXmlRequest( ) { ParameterXml = "<importexportxml><entities><entity>contact</entity></entities><nodes /><securityroles /><settings /><workflows /></importexportxml>" }; PublishXmlResponse publishResponse = (PublishXmlResponse)_service.Execute( publishRequest ); }
The query.columnsetxml = entitySchema.XmlColumnSetSchema looks like this:<fetch mapping="logical" count="50" version="1.0"> <entity name="contact"> <attribute name="donotemail" /> <attribute name="donotphone" /> <attribute name="emailaddress1" /> <attribute name="firstname" /> <attribute name="fullname" /> <attribute name="lastname" /> <attribute name="mobilephone" /> <attribute name="modifiedon" /> <attribute name="ryland_preferredphonetype" /> <attribute name="telephone1" /> <attribute name="telephone2" /> <filter> <condition attribute="donotphone" operator="eq" value="0" /> </filter> </entity> </fetch>
The view is being created in Contact / MyViews which is correct, but the only column being displayed in the "Full Name". Any ideas of what I am doing wrong? Thanks in advance.<columnset> <column>donotemail</column> <column>donotphone</column> <column>emailaddress1</column> <column>firstname</column> <column>fullname</column> <column>lastname</column> <column>mobilephone</column> <column>modifiedon</column> <column>ryland_preferredphonetype</column> <column>telephone1</column> <column>telephone2</column> </columnset>
Answers
I am now setting layoutxml property (query.layoutxml = entitySchema.XmlLayoutSchema).
All columns are being displayed in the Advance Find. However when I try to run the query from the Contacts views it returns this error: To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable items. Does anyone know if this is related to the layoutxml or is this a seperate issue?<grid name="resultset" object="1" jump="fullname" select="1" icon="1" preview="1"> <row name="result" id="contactid"> <cell name="donotemail" width="300" /> <cell name="donotphone" width="150" /> <cell name="emailaddress1" width="150" /> <cell name="firstname" width="150" /> <cell name="fullname" width="150" /> <cell name="lastname" width="150" /> <cell name="mobilephone" width="150" /> <cell name="modifiedon" width="150" /> <cell name="ryland_preferredphonetype" width="150" /> <cell name="telephone1" width="150" /> <cell name="telephone2" width="150" /> </row> </grid>
Note: I am able to go to the Advance Find and execute the view and it works fine.
Thanks.- Marked As Answer bysburtonctr Friday, November 06, 2009 8:15 PM
- I added the contactid early and it was still erroring and all my attributes are searchable. I made some changes and it fixed the problem.
1. The object attribute in the grid tag was set to 1 and it should have been 2
2. I set the query.statecode to Active
query.statecode = new UserQueryStateInfo( );
query.statecode.value = UserQueryState.Active;
It works now! Thanks everyone.- Marked As Answer bysburtonctr Friday, November 06, 2009 8:15 PM
All Replies
- the property layoutXml is the one which store the column display... but it is marked as "For internal use only" in the sdk...
Anyway, I wrote a view layout replication program and you can edit this property
NB: This program is available on my blog...
My blog : http://mscrmtools.blogspot.com You will find: Form Javascript Manager (export/import javascript from forms) ISV.Config Manager (graphical ISV.config edition - export/import) View Layout replicator (customize one view and replicate to others) And others (use tool tag on my blog) I am now setting layoutxml property (query.layoutxml = entitySchema.XmlLayoutSchema).
All columns are being displayed in the Advance Find. However when I try to run the query from the Contacts views it returns this error: To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable items. Does anyone know if this is related to the layoutxml or is this a seperate issue?<grid name="resultset" object="1" jump="fullname" select="1" icon="1" preview="1"> <row name="result" id="contactid"> <cell name="donotemail" width="300" /> <cell name="donotphone" width="150" /> <cell name="emailaddress1" width="150" /> <cell name="firstname" width="150" /> <cell name="fullname" width="150" /> <cell name="lastname" width="150" /> <cell name="mobilephone" width="150" /> <cell name="modifiedon" width="150" /> <cell name="ryland_preferredphonetype" width="150" /> <cell name="telephone1" width="150" /> <cell name="telephone2" width="150" /> </row> </grid>
Note: I am able to go to the Advance Find and execute the view and it works fine.
Thanks.- Marked As Answer bysburtonctr Friday, November 06, 2009 8:15 PM
- Add this to your fetchXml:
<attribute name="contactid" />
Dave Berry - The other thing to do is make sure every attribute you're retrieving with the fetch has the Searchable field set to "Yes".
Dave Berry - I added the contactid early and it was still erroring and all my attributes are searchable. I made some changes and it fixed the problem.
1. The object attribute in the grid tag was set to 1 and it should have been 2
2. I set the query.statecode to Active
query.statecode = new UserQueryStateInfo( );
query.statecode.value = UserQueryState.Active;
It works now! Thanks everyone.- Marked As Answer bysburtonctr Friday, November 06, 2009 8:15 PM

