Thursday 21 March 2013

Javascript IntelliSense not working in Visual Studio 2010 for Sharepoint 2010 and 2013 ( Client Object Model )

I should publish this article long time ago, but it is one of them. I normally know all the commands from jQuery, so I don’t really need to have IntelliSense. Today I was doing some work with the Client Object Model from Sharepoint in javascript, and I noticed straight away that the IntelliSense was not working in Visual Studio 2010 again.

I am going to post some tricks which sometimes makes this IntelliSense bug to work in Visual Studio.

First of all, let’s go to implement the Client Object Model how “officially” needs to be implemented:

Enabling ECMA Client Object Model IntelliSense for an Application Page

This procedure registers script tags in an application page. This allows Visual Studio 2010 to provide ECMA Client Object Model IntelliSense for the application page.

To enable ECMA Client Object Model IntelliSense for an application page

  1. In the Solution Explorer window, right-click the project node, point to Add, and then click New Item.
  2. In the New Item dialog box, in the Installed Templates pane, expand Visual C#, expand SharePoint, and then click 2010.
  3. To the right of the Installed Templates pane, click Application Page.
  4. In the Name box, type the name that you want to use for your application page.
  5. Click Add.
  6. On the application page, in the PageHead content placeholder, add the following code.

Note: by using an undefined constant, Visual Studio will provide Intellisense while the <script> element is omitted from the actual page rendering

<% #if SOME_UNDEFINED_CONSTANT %>
<script type="text/javascript" src="/_layouts/SP.debug.js" ></script>
<% #endif %>

Notice that the Visual Studio 2010 status bar indicates that it is updating the JavaScript IntelliSense for your page, as shown by the following illustration.

Ff798328.a39fca9a-f7f9-49d2-8747-a5e3bc70f755(en-us,PandP.10).png

On the application page, in the PageHead content placeholder, use the following code to add another script tag and create a JavaScript function.

<script type="text/javascript" language="javascript">
  ExecuteOrDelayUntilScriptLoaded(test, "sp.js");
  function test() {
    this.ClientContext = SP.ClientContext.get_current();
  }
</script>

Notice the IntelliSense is available for the ECMA Client Object Model, as shown by the following illustration.

Ff798328.a1d7e208-694a-419e-a22a-97acaf3bfb4a(en-us,PandP.10).png

Note: Depending on the portions of the object model that you are working with, you might need to add script tags that reference other SharePoint Client Object Model .js files. These files can be found in the _layouts virtual directory.


Enabling ECMA Client Object Model IntelliSense for a Visual Web Part


This procedure registers script tags in a Visual Web Part. This allows Visual Studio 2010 to provide ECMA Client Object Model IntelliSense for a Visual Web Part.

To enable ECMA Client Object Model IntelliSense for a Visual Web Part


  1. In the Solution Explorer window, right-click the project node, point to Add, and then click New Item.
  2. In the New Item dialog box, in the Installed Templates pane, expand Visual C#, expand SharePoint, and then click 2010.
  3. To the right of the Installed Templates pane, click Visual Web Part.
  4. In the Name box, type the name that you want to use for your Visual Web Part.
  5. Click Add.
  6. In the Visual Web Part .ascx file, add the following code.
    <% #if SOME_UNDEFINED_CONSTANT %>
     <script type="text/javascript" src="/_layouts/MicrosoftAjax.js" ></script>
     <script type="text/javascript" src="/_layouts/SP.debug.js"></script>
    <% #endif %>

    Notice that the Visual Studio 2010 status bar indicates that it is updating the JavaScript IntelliSense for your page, as shown by the following illustration.

    Ff798328.ae6fe69f-bc73-4a0f-85c6-7865da239c87(en-us,PandP.10).png


  7. In the Visual Web Part ASCX file, use the following code to add another script tag and create a JavaScript function.
    <script type="text/javascript" language="javascript">
      ExecuteOrDelayUntilScriptLoaded(test, "sp.js");
      function test() {
        this.ClientContext = SP.ClientContext.get_current();
      }
    </script>

    Notice that IntelliSense is now available for the ECMA Client Object Model, as shown by the following illustration.

    Ff798328.0449199a-bc46-4828-9103-6392ebdaedc5(en-us,PandP.10).png

    Ff798328.note(en-us,PandP.10).gifNote:

    Note: Depending on the portions of the object model that you are working with, you might need to add tags that reference other SharePoint Client Object Model .js files. These files can be found in the _layouts virtual directory.
    You should remove the references to the .js files that enable IntelliSense when you deploy the Visual Web Part in a production environment.


Official way not working! Additional trick 1


Opps, It seems, that the official way didn’t work… let’s go to apply little tricks, I will recommend you do all of them. This can be used for any js file.


To get Intellisense to work again, I ended up resetting my Visual Studio settings (Tools | Import and Export Settings):

ResetSettings

then go ahead and reset to your preferred default profile (I typically choose the C# profile over the Web profile). This may seem counter intuitive immediately after a new install since I hadn’t changed any settings yet, but the reset did the trick.

And voila, Intellisense in JavaScript is back.

I suspect this has something to do with VS 2010 importing some existing VS 2008 settings, so even if you don’t have problems in VS 2010 it might be a good idea to actually reset all settings just to make sure there’s a clean slate to start with.

Not working… well go to the next one…

Official way not working! Additional trick 2


Re-start  Visual Studio 2010


Not working?!… well go to the next one


Official way not working! Additional trick 3


Now let’s go to change our references a little bit, so instead to tell Visual Studio are local, let’s go to tell it is on the Internet.So if we come back to Additional trick 1, we will be changing the references. So having a server called “sp2010dev” and a site called “tr”, we will have the following reference:


For a Page:

<% #if SOME_UNDEFINED_CONSTANT %>
 <script type="text/javascript" src="http://sp2010dev/tr/_layouts/SP.debug.js"></script>
<% #endif %>
For a Webpart:
<% #if SOME_UNDEFINED_CONSTANT %>
 <script type="text/javascript" src="http://sp2010dev/tr/_layouts/MicrosoftAjax.js" ></script>
 <script type="text/javascript" src="http://sp2010dev/tr/_layouts/SP.debug.js"></script>
<% #endif %>
Try now!

Friday 15 March 2013

“external content types are not available. Contact your system administrator” in Business Connectivity Services on Sharepoint 2013.

I remember spending one or two days trying to sort out this issue. It was quite annoying, mainly because the hardest part was already developed in Visual Studio 2012, and I couldn’t see the content type from my BCS connexion.

Right, I think it will be useful to show what to do if you have this problem, the problem is basically that our External Content Type Picker is empty:
image

Option 1
Go to “Central Administration->Manage Service Applications->Business Data Connectivity Service”. Be sure you BDC Connexion is there. If it is, select it, and go to “Set Object Permissions” and set “All Authenticated Users” enable for Edit, Execute, Selectable In Clients and Set Permissions. Tick “Propagate permissions to all methods of this external content type. Doing so will overwrite existing permissions.”.
After doing this, everything should work an look like this:
image

Option 2
If you have removed the Method “ReadItem” it will be deployed but not showed it. Be sure your BDCModel has the two main methods “ReadList” and “ReadItem”:
image

 

 

 

 

 

 

 

 

Option 3
If you still having the same problem… be sure when you go to your “BDC Explorer” under Visual Studio 2012, select TypeDescriptor and the “Identifier” is select it. That is the main link between the class and the entity. For example here, I select BaseUri TypeDescriptor and I link it with BaseUri from the class.
image

Conclusion
There are more problems related. but I think this is a good start point.

Wednesday 13 March 2013

“The password supplied with the username was not correct. Verify that it was entered correctly and try again” on Sharepoint 2013

At some point I had that annoying pop up box asking to change the Sharepoint admin password. Ok I changed the password, and I went to Central Administration to create a new Web Application…

I created and I have got this message, what I think it is exactly the same I used to get in Sharepoint 2007 and Sharepoint 2010.

This is normally because the farm credentials have not been updated. To do this I always use the old fashion STSADM command.

Go to Microsoft SharePoint 2013 Products->SharePoint 2013 Management Shell and type the following:

stsadm -o updatefarmcredentials -userlogin yourdomain/youruser -password yourpassword

Enjoy!

Tuesday 12 March 2013

Getting the RSS feed from a list in Sharepoint 2013

This is an easy job, it can be done if you have been doing some work with Sharepoint 2010. The approach is exactly the same, but it will be nice to do it in Sharepoint 2013 so we can get some training with the new menus.

Right, so how do we get an RSS feed from a list?

Step 1
Create a list

Step 2
Go to the settings icon and select “Site Contents”
image

Step 3
Click in your list, now! on the top of the list, select the tab “LIST” and then “List Settings”
image

Step 4
Go to “Communications” and select “RSS settings” and be sure that “Allow RSS for this list” is ticked to “Yes”
image

Step 5
Go to your list again, select “LIST” and select “RSS Feed”. Job done!
image

Result!
image

Thursday 7 March 2013

Submitting an InfoPath 2010 form in a document library saving the form as a file and the data as particular Content Type in Sharepoint 2010

The other day one of our clients requested a massive form, I think I count 500 controls. I have never been a huge fan of InfoPath, mainly because every time I use it, becomes a little bit tricky. The client always wants to go to the extra mille, so you end building a web part and leaving the InfoPath form away.

In this case, I knew that a 500 controls form will take me months to build, so I decided the only way, was InfoPath. The requirements were simple, keep the form, and keep the data, so the client could attach a Business Intelligence process behind the results.

The tricky part for me was to create the connection and the content type for it, but as soon as you know how to do it, it is a piece of cake. Right here we go… a step by step:

  1. Open InfoPath 2010.
  2. Select “SharePoint Form Library->Design Form”.
  3. Design your form.
  4. Publish your form to be sure it is ok.
  5. Go to “File->Publish->Sharepoint Server”.
  6. A Wizard like this will be opened:

    image
  7. Enter the site and the Document Library where the form is kept.
  8. Leave this form as it is and click next.

    image
  9. Now, select “Update the form template in an existing form library”, and select the library where you are keeping the forms.

    image
  10. Now! the funny thing… click on Add and select the fields you want, and click “Next”.image

  11. Click on Finish!

Job done!, now, everytime you submit a new form it will be saved in the “Document Library” as a file (with all the data inside) and it will save the data in the columns, so you can interrogate them from any source.