Creating an View/Edit Screen based on a View using the .NET API

Less than one minute read time.

Below is a screen shot of a compound screen that populates the fields on the screen from data retrieved from a view.

This very simple page has been built using the .NET API.

It has used the method FindRecord().

Syntax is

FindRecord('Entity,vViewName',ArgString);

This is a good way of quickly displaying information from the view. But it can not be used for updating and inserting.

C# Code

    public class MyCustomPage : Web
    {
        public override void BuildContents()
        {
            //Add your content here!      
            GetTabs();
            string CompanyID = GetContextInfo("company", "comp_companyid");
            Record myRecord = FindRecord("company,vEntityCompany", "comp_companyid =" + CompanyID);//parameters as string values
 
            EntryGroup CompanyScreen = new EntryGroup("companyboxlong");
            CompanyScreen.NewLine = true; //true|false
            CompanyScreen.Title = Metadata.GetTranslation("tabnames", "company");
 
            EntryGroup PersonScreen = new EntryGroup("personboxshort");
            PersonScreen.NewLine = true; //true|false
            PersonScreen.Title = Metadata.GetTranslation("tabnames", "contact");
 
            AddContent(CompanyScreen.GetHtmlInViewMode(myRecord));
            AddContent("
");
            AddContent(PersonScreen.GetHtmlInViewMode(myRecord));
 
        }
    }

  • You can update fields but only if the fields belong to the referenced entity. If they are from the joined view and not in the referenced entity, the write back doesn't occur. You don't get an error, but nothing is saved to the other records. SQL does allow you to write back data using a view but I guess CRM doesn't and my guess is either managing context or referential integrity in the database.

    What I did was to allow the user to click change on the screen but force each field that is not in the referenced entity to be read only in the createscript. This seems to cause no problems to CRM. Hopefully this isn't a "hack" that gets "fixed".

    Nice work Jeff, I like it.