About Me

My photo
Currently working as a Pen Tester, I'm interested in Android and web apps.

Tuesday, 31 August 2010

Navigating using a drop down list and inserting values in the drop down list to a SharePoint List

Essentially the web application I'm working on contains three categories where everyt piece of data in the application falls under. An example of this would be where each person who visits the website falls under one of three age categories 18-25, 26-35 and 36-50. Depending on what age category they're in would produce a webpage with products marketed at them in a drop down list.

So how in SharePoint do you present the user with a unique set of products depending on what category they fall under? I decided to use some JavaScript that was called when the user selected their cateory from a drop down list. When selected the drop down would simply navigate to an unique page that contained the same custom form which I created in the post Populating a 'Drop Down List' from a SharePoint List but each page's drop down menus would be populated from a different SharePoint List. So the user selects that they are 18-25 and the drop down list on the page would have products marketed at them. If the user selects 26-35 the drop down list is populated with different products than the 18-25 category and so on.

To get the JavaScript working I placed it between the <head> tags on the master page of the SharePoint site. Location of master page is shown in the picture below and the JavaScript code is also below;

<head>
    <script language="JavaScript">
        <!--
            function navigate(form) {
            var OptionIndex=form.ProductTypeURL.selectedIndex;
            parent.location = form.ProductTypeURL.options[OptionIndex].value;}
        //-->
    </script>
</head>

The drop down menu was created with the following code;

<select name="AgeURL" size="1" language="javascript" onchange="navigate(this.form);">
   <option selected="">18-25 </option>
   <option value="middle.aspx">26-35</option>
   <option value="oldest.aspx">36-50 </option>
</select>

I decided the easiest way to insert the values from the above drop down menu into a SharePoint List was to have a text field that would be pre-populated with the value selected in the drop down. So if the value selected in the drop down was 35-50 then the value in the text field was 35-40. 


In SharePoint Designer create a text field like the one below;



Click the arrow beside the text field and assign it to the data field, essentially what SharePoint List do you want the value in the text field to go into.




The text field would not be visible to the user. The full code for this text field is;
<asp:TextBox runat="server" id="ff15{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff15',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Person_x0020_Age')}" text="18-25" visible="false" />

The main areas to note in the above code are;
  • text="18-25" - change from text="{@FSObjType}" to insert your value
  •  visible="false" /> - add this to make the field invisible to user

Thursday, 26 August 2010

SharePoint Designer Error when Opening SharePoint Page

I've been adjusting and changing the Custom List Form I created in the post Populating a 'Drop Down List' from a SharePoint List and I've run into an error. When I try to open the Web Part page with the Custom List Form in SharePoint Designer 2007 I get the following error;


The server could not complete your request.
Contact your Internet service provider or Web
server administrator to make sure that the
server has the FrontPage Server Extensions or
SharePoint Services installed.

For more specific information, click Details
button.

When I click the 'Details' button I get the following text;

soap:ServerServer was unable to process request. ---> An unexpected error occurred while opening this page. For assistance, contact your site administrator.

Now I think it has something to do with inserting the Custom List Form on the page and then going ahead and changing the List in SharePoint. For example I have changed some drop down menus to drop down menus with  an area for the user to put their own value along with other changes to how the user can input data into the List.



Changing the highlighted area above has the following effect on the user input;

From
Drop Down

To
Drop Down with optional value



As you can see on top of the 'not being able to open the page' issue, I'm having an issue with populating the drop down list when I add an area for the user to specify their own value, but that for another post. I think the best thing to do is meticulously plan out how the user will enter their details and then create a custom list form. But I'm kind of tinkering around with inputs to make the application as user friendly as possible, so I think inputs will inevitably change.

Anyway the current solution for this problem is deleting the page and starting again. When I find a better solution I'll post it up.

Wednesday, 25 August 2010

Appreciating how fast you can Develop on SharePoint

I've been working with SharePoint now for just over a month and I have to admit building a web application is quick and fairly easily. My first impressions of the platform were not good and I may have been a bit harsh on some points, but I do still feel if this application was to grow it would need a relational database. I know it is possible to import a relational database into SharePoint but the way SharePoint is set up for this project it's not possible.

SharePoint has helped so much with the speed of the development, I could not have gotten this far with the prototype if I was building it from scratch using ASP or JSP or PHP etc. It is also a testament to Microsoft for the support they have for their products. There are so many official resources on top of the large number of developer communities, which has helped immensely in troubleshooting and I've gotten some fantastic tips.

Everything is not exactly clear sailing as I am finding some restrictions developing for the platform. In some cases I can see where lower level coding would provide an easy solution but on SharePoint you need to use a work around. I suppose on the other hand lower level coding would be time consuming and in the end, there are work arounds. Solutions for SharePoint has forced me to think in a different way than I am used to when creating products for the web, and that has to be a good thing.

At the moment I'm working on two problems I'm having with SharePoint. One of which I've just about solved and I will post up a tutorial when I'm finished.

Wednesday, 18 August 2010

Removing 'Title' from a SharePoint List

Every time you create a List that pesky 'Title' field is automatically created. This post will explain how to get rid of it.

EDIT -> Have a look at This Post before proceeding

A new List;


Step 1
To start click Settings > List Settings


The Settings Page;



Go to Advance Settings under General Settings and check the radio button to 'Yes' where it says 'Allow Management of Content Types?'.


Once you click okay your back in the Settings Screen. Scroll down to Item under Content Types and then click on Title.


Once Title is clicked select the radio button 'Hidden (Will not appear in forms)' and press OK.

That gets rid of the 'Title' field.


Optional
Change the Views
On the Settings page scroll down to 'Views' and click on 'All Items'


Now here you can select what Items will be in all the Views presented to the user. Select which ones you want and what positions you want them at.


Once you press OK and then go to create a new Item you should only have the Items you have selected here within the new Item form. I'll post up any other solutions as I discover them.

Tuesday, 17 August 2010

Populating a 'Drop Down List' from a SharePoint List

I've been playing around with SharePoint Lists and I've found a handy way of populating a drop down list in SharePoint with another SharePoint List. Here is a quick guide;

In this example I'm creating a place where a user enters their name and then selects what country they are from. So I create two Lists
  • User Details
  • Countries
User Details will have two columns; 'Name' and 'Country'.

Step 1
Create the Custom Lists
Site Actions > Create > Custom List
Add columns;

Settings > Create Column
or Settings > List Settings > Create Column


The above screen shot is of the Country column being created within the User Details List. Notice that instead of filling in a list of countries in this column I simply put 'none' in the "Type each choice on a separate line" box. I'm not listing countries here because I want to populate this from a SharePoint List that I've made called Countries.


Step 2
Now create a Document Library
Site Actions > Create > Document Library

Then create a Web Part page. Choose the layout as a full page and add it to the document library just created.

Step 3
Launch SharePoint Designer and open up the Web Part page just created.


Delete the 'click to insert Web Part' from the page and add a Custom List form to the page.
Insert > SharePoint Controls > Custom List Form...


Then select the List you want to populate, in this case it's the User Details List.

Now right click where the Country drop down is and select the following;
Format Item as > Drop Down List


Make sure the drop down list, which will now have unbound, is not selected (click beside it). Go over to the right of SharePoint Designer 2007 to the window with the tabs Toolbox, Data Source Library... etc. and click the 'Data Source Library' tab.
*If it is not there go to the top toolbar (File, Edit, View...) and click on Task Panes -> Data Source Library.

Find the List that you want to populate the drop down with, in this case the Countries list will populate the drop down. Click the list and click inset data source control.

Now go back to the drop down and click the little arrow and then click Data Fields.

A window will pop up, the first option is the data field just leave it as this is the one selected (although you can change it if you want). In this case the data field selected is Country in the User Details List.

There is also an option here to present the user with data from one column in the List and once selected by the user a value is entered from a different column in the List from a corresponding row. This is handy if you want a description for the data presented to the user but want a number value to be entered into the List.

Step 4
All that needs to be done now is to change the view the user gets when they are creating a new Item from the default view to your new Web Part page with the custom form.

Go to the Lists on the left hand side of SharePoint, expand Lists and then right click the User Details List and click Properties.



Then in list properties click the 'Supporting Files' tab and do two things

  • *Very important that under 'Content type specific forms:' you change it from 'Folder' to 'Item'.
  • Then change the 'New item form' to the Web Part page with the custom form (Pages/userdetails.aspx) by pressing browse and locating you new page.



All done. Now when a user clicks 'New Item' in SharePoint they will be brought to the Web Part page and the drop down list will be populated from another SharePoint List.

Friday, 13 August 2010

Going Ahead with SharePoint

We sat down this week and it was decided to go ahead with SharePoint even if some of the features are sacrificed. The main aim of this project is to have a prototype ready so that customers can say they like it or they don't.

I've been messing around with the data and SharePoint Lists and I will admit it looks handy to throw something together. I've had to rethink a lot of the original design as I based it on a relational database. I've put some Lists up and messed around with them, but I'm still waiting on SharePoint Designer to be installed on my machine. I've downloaded the free copy of SharePoint Designer 2007 onto my laptop but I can't really use it with the wireless network in here. Maybe with SharePoint Designer I will find a way of including all the features, I have some ideas and I'll update here with the progress.

Thursday, 5 August 2010

Database Design

I'm waiting on a meeting to discuss my conclusion that SharePoint is the wrong platform and then hopefully choose another platform I suggested. While I'm waiting I've decided to go ahead with designing the database. So much stuff has come flooding back on databases I haven't done since first year.

To design the database I am modelling it on the ANSI/SPARC architecture. This architecture has been around for years and it is tried and tested. It allows the views of the database to be separated from the actual physical representation. The external level in the architecture allows different users to have a different view of the database e.g. admin will have a different view from a normal user. The internal level is how the data is actually stored where it is concerned with disk space, indexes, compression, security etc.

When designing the database the first part that is considered, and my case is no different, is the conceptual level where entities, relationships, constraints etc. are all planned out. I am using the following process to design this conceptual level;

  • Determine the purpose of the database

  • Find and organise the information

  • Divide the information into tables

  • Divide information in the tables in columns (attributes)

  • Set primary keys for each table

  • Identify relationships (cardinality)

  • Refine the design (populate with test data and run queries then adjust design according to tests i.e. add another table or attribute to a table etc.

  • Apply normalisation rules
Database Design Programs
In my search for free ER diagram tools I stumbled upon a program called RISE, - http://www.risetobloome.com/Page_1_S.aspx?ITEM=1853 as the computer in the office here only has a watered down version of Microsoft Visio that doesn't have the option to create ER diagrams. Anyway the program is good, got the job done and I produced two ER diagrams from it that the boss was happy with. Then I came across MySQL Workbench - http://wb.mysql.com/ which I've never seen before, since I haven't designed a database in ages. It's even better than RISE because I've created the database from an ER diagram without the need to code each and every SQL table and relationship etc. etc. You can forward engineer your diagram and the database goes right into a selected MySQL database. What more do you want. You can also perform CRUD operations on the database from Workbench. It is a great tool and I'm really happy with it.
Issues
A couple of things came up during the design, one of which was the many-to-many relationships. I've dealt with this by using junction tables to break up the relationships from a many-to-many to one-to-many or zero-to-many. A good example, that I'm going to rob but it's probably been used hundreds of times anyway, is the situation of the orders table and the products table. One order can contain many products. One product can appear on many orders. This causes the problem of where to put the foreign keys to link these two tables without getting duplicate information. The pk ProductId as a foreign key in the orders table would mean that for more than one product per order there would be more than one record on the orders table. The pk OrderId as a foreign key in the products table would mean more than one record in the products table for each product. So the junction table called OrderDetails would take both the ProductId in the products table and the OrderId in the orders table as foreign keys to form a primary key. This solves the problem of the many-to-many relationship and the picture below illustrates the point.
Foreign key problems also occurred mainly in the form of the error -
errno:121 (Duplicate key) with CREATE TABLE
or
ERROR 1005 (HY000): Can't create table '.' (errno:121)
This means that foreign keys must be unique to the database, so you cannot have a foreign key in one table with the same name as a foreign key in another. One way I was going to check the foreign keys was to painstakingly review each one in the ER diagram. However, thanks to a blog I came across I used the following query to review the foreign key names;
SELECT
constraint_name,
table_name
FROM
information_schema.table_constraints
WHERE
constraint_type = 'FOREIGN KEY'
AND table_schema = DATABASE()
ORDER BY
constraint_name;
This query is taken from http://thenoyes.com/littlenoise/?p=81
I'm going to run some tests on the database with some queries and continue to improve it. Hopefully I get to sit down and discuss not using SharePoint and then all I have to do is rename this blog!?