Wednesday, 8 January 2014

Add item into SharePoint list using javascript

In this blog, we learn how to add item into SharePoint list using JavaScript.

Below function add to the content editor webpart or into your core .js file,and call on link click or button click.

<script type="text/javascript">
// Make sure the SharePoint script file 'sp.js' is loaded before your
// code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
function createListItem()
{
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('InwardOutward');
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
   oListItem.set_item('Title', 'My New Item!');
   oListItem.update();
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded()
{
    alert('Item created: ' + oListItem.get_id());
 }
function onQueryFailed(sender, args)
{
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>

<a href="javascript:createListItem();"><img alt="Add" src="/Image_/add.png" border="0"/></a>

While using JavaScript to add item into list following error may occurred:

Request failed. List data validation failed.undefined

Error Message:

Request failed. List data validation failed.undefined

Problem Description:

I wrote JavaScript function to add item into SharePoint List but I getting below error shown in following figure.





I got above error because I kept column validation in my one of the Date Column,





I remove column level validation from my List, I wrote validation in JavaScript function only.





That’s all and finally my Item created using JavaScript…






Tuesday, 7 January 2014

Unable to get property get_current of undefined or null reference

Error Message:

Unable to get property 'get_current' of undefined or null reference.

Problem Description:

I wrote JavaScript function in my core .js file and calling from SharePoint list form.


SharePoint Form

Core .js file



In that function i.e."TravelRequestAdminDocumentReceived()" I am trying to get some information about the current context through the SharePoint JavaScript object model and am getting below error.




Solution:

This error is occurred because SP.js file not get loaded. To load SP.js file before our function we need to use following function

ExecuteOrDelayUntilScriptLoaded(TravelRequestAdminDocumentReceived, "sp.js"); 




Remark : After your custom function in ExecuteOrDelayUntilScriptLoaded don’t use brackets “()”.

Sunday, 5 January 2014

Visio Services is unable to load

Error Message:

Visio Services is unable to load this Web Drawing because the Web Drawing URL web part setting is invalid. To resolve this issue, verify that the Web Drawing URL is properly formed and refers to an existing .VDW file.

Problem Description:

I found this error while adding visio webpart on SharePoint 2010 webpart page.
I got this error message because at the time of saving visio file  I kept by default extension i.e. “Drawing”.



Solution:

As shown in figure we need to change visio file extension as “Web Drawing”.
The Visio Web Drawing (*.VDW) is a new Visio file type that allows diagrams to be rendered in full fidelity in the browser using Visio Services on SharePoint 2010.

Product applies to:
SharePoint Server 2010


Saturday, 4 January 2014

An unhandled exception occurred in the silver light application

Problem Description:
 An unhandled exception occurred in the silver light application

The site did not allow me creating any new item on one of my sub sites and an error message as “An unhandled exception occurred in Silverlight Application” as in screenshot below.




Steps to solve problem:

1.       Go to Central Administration

2.       Go to Application Management > Manage Web Application

3.       Select the SharePoint Site Collection where you are facing the issue and Click General Settings on the ribbon

4.       Set Web Page Security Validation to “On” and save the changes.




5.       That’s all...Check with your site.

Product applies to:
SharePoint Server 2010
      SharePoint Foundation 2010

Enable anonymous access in sharepoint 2010

In this blog, we learn how to enable anonymous access in sharepoint 2010.
Follow below steps:

1.     Starting in Central Administration, under Application Management, click on the Manage web applications.



2.     Make sure you select the site you want to enable anonymous access and click on the Authentication Providers icon.



3.     On the Authentication Providers pop-up window click on the Default zone.



4.     Under Edit Authentication, check Enable anonymous access and click Save.




5.     Going back to Web Application Management click on the Anonymous Policy icon.




6.     Under Anonymous Access Restrictions select your Zone and set the Permissions to None – No policy and click Save.




7.     Now, web application will allow anonymous access to be set. So, navigate to your top level site collection for the web application. Click the Site Actions > Site permissions.




8.     Under Permission Tools, click Anonymous Access icon and set the permissions to Entire Web site and click OK.







 That’s all...
 Now you should have Anonymous Access enabled.


Product applies to:
SharePoint Server 2010
      SharePoint Foundation 2010




How to add and edit item into the Welcome drop-down menu in Sharepoint 2010


In this blog, we learn about how to add and edit item into the Welcome drop-down menu in Sharepoint 2010.

To add item into the Welcome drop-down menu follow below steps:


1.     Create an Empty SharePoint Project



2.     Updating the Solution Feature



3.     Create an Element : for that we need to create an element to attach to our feature, to do that right-click on the project and add a new item, then choose "Empty Element".



4.     Edit our element to reflect what we needed.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
        Id ="CustomMenu_MyProfile"
        GroupId="PersonalActions"
        Location="Microsoft.SharePoint.StandardMenu"
        Sequence="1000"
        Title="My Profile"
        Description="View and Update my Information" 
        ImageUrl="_layouts/images/MyProfile.gif">
    <UrlAction Url="/SitePages/My%20Profile.aspx"/>
  </CustomAction>
</Elements>


5.     Package your Sharepoint Solution

6.     Add and Install your Solution to Sharepoint

7.     Now our menu item is ready, check it out






Product applies to:
SharePoint Server 2010
      SharePoint Foundation 2010