{"id":677,"date":"2010-08-28T17:57:51","date_gmt":"2010-08-28T15:57:51","guid":{"rendered":"http:\/\/www.itidea.nl\/?p=677"},"modified":"2015-09-08T20:30:57","modified_gmt":"2015-09-08T18:30:57","slug":"bcs-model-a-simple-editable-model","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/bcs-model-a-simple-editable-model\/","title":{"rendered":"BCS model \u2013 a simple editable model"},"content":{"rendered":"<p>Let\u2019s adjust the <a href=\"https:\/\/www.itidea.nl\/index.php\/bcs-model-a-simple-read-only-model\/\">previous model <\/a>to enable adding new items and edit existing ones.\u00a0<\/p>\n<p>Open the previous project and open the design view of the model (.bdcm). In the BDC Method Details window select \u2018Add a method\u2019 and \u2018Create Creator Method\u2019. Two parameters are created, one for input, one as return parameter. Check the type names of both Type Descriptors. Both have to be set to the Customer entity. Probably they are set correctly already, because of the previous ReadList and ReadItem methods. Open the BDC Explorer and make sure the other type descriptors (the ones that make up a Customer) are present at the input and return parameter. Probably they also are there already.<br \/>\nCheck the properties of the type descriptors of the input parameter \u2018NewCustomer\u2019. The property CreatorField is set to True here. With this parameter you can control the fields displayed on the new form. Since our CustomerId is an auto increment field, delete this type descriptor from the input parameter.<br \/>\nThat\u2019s it for the configuration, the only thing left is to update the code at the CustomerService class. As in the previous post I use Linq to Sql, an example:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static Customer CreateCustomer(Customer newCustomer)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 using (LinqToSQLClassCustomerDataContext db = new LinqToSQLClassCustomerDataContext(CONNECTION_STRING))\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CustomerBasic newItem = new CustomerBasic();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 newItem.CustomerName = newCustomer.CustomerName;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 newItem.CustomerCity = newCustomer.CustomerCity;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 db.CustomerBasics.InsertOnSubmit(newItem);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 db.SubmitChanges();\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Customer returnCust = new Customer\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CustomerId = newCustomer.CustomerId\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return returnCust;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n<\/pre>\n<p>Deploy the solution and check out the list created on the previous version of this solution. The list seems fine and at the List Tools tab, Items, the New Item button is enabled. Select this button.<br \/>\nWhen expecting the new form, a Runtime Error occurs.<br \/>\nOpen SharePoint Designer and select the list. In the next screen several items of the list are displayed, e.g. Settings, Views and\u2026 Forms! As you can see at the picture below there is no NewForm, that\u2019s why the error occurs.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoNewForm.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-678\" title=\"BDCNoNewForm\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoNewForm.png\" alt=\"\" width=\"662\" height=\"104\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoNewForm.png 662w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNoNewForm-300x47.png 300w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/a>\u00a0<\/p>\n<p>And checking the logfile:<br \/>\nSPException thrown: Message: Unable to find the default new form for list<br \/>\nSays the same, no New Form present.\u00a0<\/p>\n<p>To get a full functioning list, create a new list based on the External Content Type and the NewForm is present:<br \/>\n\u00a0<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNewFormCreated.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-684\" title=\"BDCNewFormCreated\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNewFormCreated.png\" alt=\"\" width=\"663\" height=\"113\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNewFormCreated.png 663w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCNewFormCreated-300x51.png 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/a>\u00a0<\/p>\n<p>Ofcourse SharePoint Designer can help you out without creating a new list by selecting NewForm at the Forms section:<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCreateNewFormSPD.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-685\" title=\"BDCCreateNewFormSPD\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCreateNewFormSPD.png\" alt=\"\" width=\"664\" height=\"397\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCreateNewFormSPD.png 664w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCCreateNewFormSPD-300x179.png 300w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/a><\/p>\n<p>When selecting \u2018New Item\u2019 in the browser a new Customer can be added.<br \/>\n<a href=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewNewFormSPDInBrowser.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-686\" title=\"BDCViewNewFormSPDInBrowser\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewNewFormSPDInBrowser.png\" alt=\"\" width=\"749\" height=\"462\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewNewFormSPDInBrowser.png 749w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2010\/08\/BDCViewNewFormSPDInBrowser-300x185.png 300w\" sizes=\"auto, (max-width: 749px) 100vw, 749px\" \/><\/a>\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>The updater method is just as simple.<br \/>\nIn the BDC Method Details window select \u2018Add a method\u2019 and \u2018Create Updater Method\u2019. One input parameter is created \u2018customer\u2019. Check the type name of the Type Descriptor. This has to be set to the Customer entity. Probably it is set correctly already, because of the previous defined methods. Open the BDC Explorer and make sure the other type descriptors (the ones that make up a Customer) are present at the input parameter. Probably they also are there already. Set the Read Only property of the CustomerId type descriptor to false and leave the Updater Field property set to True.\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>Now update the code for the updated method to actually update the Customer.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static void UpdateCustomer(Customer customer)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 using (LinqToSQLClassCustomerDataContext db = new LinqToSQLClassCustomerDataContext(CONNECTION_STRING))\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CustomerBasic updateItem = (from c in db.CustomerBasics\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 where c.CustomerId == customer.CustomerId\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 select c).FirstOrDefault();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 updateItem.CustomerName = customer.CustomerName;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 updateItem.CustomerCity = customer.CustomerCity;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 db.SubmitChanges();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n<\/pre>\n<p>\u00a0<\/p>\n<p>Deploy the solution and take a look at the list created with the previous version of the solution. Same story: Runtime Error; Edit Form not present. SharePoint Designer to the rescue: create a new Edit Form and voila!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s adjust the previous model to enable adding new items and edit existing ones.\u00a0 Open the previous project and open the design view of the model (.bdcm). In the BDC Method Details window select \u2018Add a method\u2019 and \u2018Create Creator &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/bcs-model-a-simple-editable-model\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[32,20,42,21,6],"class_list":["post-677","post","type-post","status-publish","format-standard","hentry","category-sharepoint-2010","tag-bcs","tag-c","tag-sharepoint-2010","tag-sharepoint-designer-2010","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=677"}],"version-history":[{"count":19,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/677\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/677\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}