Tuesday, August 18, 2015
Adding Button in calculated Field in SharePoint 2013
Add button in the calculated field in SharePoint 2013 list definition:
<Field Name=”Accept” ID=”{1F7328C7-D7F0-4B94-BB15-01859CD28CF2}” DisplayName=”AcceptorDecline” Type=”Calculated” ResultType=”Number” ReadOnly=”TRUE” JSLink=”/_layouts/15/CCAR.SP.Common.Lists/UserRecertification/UserRecertificationScripts.js”>
<Formula>
=”<div id=’divAccept’> <input type=’button’ name=’btnAccept’ id=’btnAccept’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’Yes’)”” value=’Approve’/>
<input type=’button’ name=’btnDecline’ id=’btnDecline’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’No’)”” value=’Decline’ /></div>”
</Formula>
<FieldRefs>
<FieldRef Name=”URID” />
</FieldRefs>
</Field>
<Formula>
=”<div id=’divAccept’> <input type=’button’ name=’btnAccept’ id=’btnAccept’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’Yes’)”” value=’Approve’/>
<input type=’button’ name=’btnDecline’ id=’btnDecline’ onclick=””UpdateApproveorDecline(‘”&[URID]&”‘,’No’)”” value=’Decline’ /></div>”
</Formula>
<FieldRefs>
<FieldRef Name=”URID” />
</FieldRefs>
</Field>
//UserRecertificationScripts.js code
function UpdateApproveorDecline(URID, ApproveorDecline) {
if (!isEmpty(URID))
{
GetListID(URID, ApproveorDecline);
}
}
{
GetListID(URID, ApproveorDecline);
}
}
function GetListID(URID, ApproveorDecline)
{
if (!isEmpty(URID))
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle(‘User Recertification’);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=\’URID\’/><Value Type=\’Text\’>’ + URID + ‘</Value></Eq></Where></Query></View>’);
this.collListItem = list.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
{
if (!isEmpty(URID))
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle(‘User Recertification’);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<View><Query><Where><Eq><FieldRef Name=\’URID\’/><Value Type=\’Text\’>’ + URID + ‘</Value></Eq></Where></Query></View>’);
this.collListItem = list.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
{
//Get the current item then get the item ID
var currentItem = listItemEnumerator.get_current();
//Getting the values to pass to the popup function
var itemid = currentItem.get_item(“ID”);
UpdateListItem(itemid,ApproveorDecline)
}
}),
Function.createDelegate(this, OnLoadFailed));
}
}
}
var currentItem = listItemEnumerator.get_current();
//Getting the values to pass to the popup function
var itemid = currentItem.get_item(“ID”);
UpdateListItem(itemid,ApproveorDecline)
}
}),
Function.createDelegate(this, OnLoadFailed));
}
}
}
function UpdateListItem(itemid, ApproveorDecline)
{
{
if (!isEmpty(itemid))
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
{
var clientContext = new SP.ClientContext.get_current();
if (!isEmpty(clientContext))
{
var webSite = clientContext.get_web();
var list = webSite.get_lists().getByTitle(‘User Recertification’);
this.oListItem = list.getItemById(itemid);
oListItem.set_item(‘Accept_x002f_Decline’, ApproveorDecline);
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
alert(“Accept/Decline set to ” + ApproveorDecline);
}),
Function.createDelegate(this, OnLoadFailed));
}
var list = webSite.get_lists().getByTitle(‘User Recertification’);
this.oListItem = list.getItemById(itemid);
oListItem.set_item(‘Accept_x002f_Decline’, ApproveorDecline);
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args)
{
alert(“Accept/Decline set to ” + ApproveorDecline);
}),
Function.createDelegate(this, OnLoadFailed));
}
}
}
}
function OnLoadFailed(sender, args) {
//Displays an error in case the request fails
alert(“Request Failed: JSOM Error, ” + args.get_message() + ‘\n’ + args.get_stackTrace());
}
//Displays an error in case the request fails
alert(“Request Failed: JSOM Error, ” + args.get_message() + ‘\n’ + args.get_stackTrace());
}
Missing “Save Site as Template” for Publishing Sites in SharePoint 2013?
Summary : Missing “Save Site as Template” for Publishing Sites in SharePoint 2013?, How to Save Publishing Sites as Template in SharePoint 2013,Workaround to Save Site as Template in Publishing Site Template.
One of the old and well known workarounds for this was to directly navigate to “_layouts/savetmpl.aspx” application page and save the site Template. This workaround however does not work as expected in SharePoint 2013 sites.
In a Typical SharePoint 2013 Publishing Site, if you try to navigate to “_layouts/savetmpl.aspx” you would get the below error –
“The “Save site as template” action is not supported on this site.”
The url “_layouts/savetmpl.aspx” failed on the Publishing site because by default, in at Typical Publishing Site in SharePoint 2013, “SaveSiteAsTemplateEnabled” is set as “false”. Setting this switch as true would re-enable us to use “_layouts/savetmpl.aspx” to save a Typical Publishing Site in SharePoint 2013.
The easiest way to set SaveSiteAsTemplateEnabled as true is by using Site options in SharePoint Designer 2013.
Lets look the Steps –
Lets look the Steps –
1. Open you Publishing Site in SharePoint Designer 2013.
2. In SharePoint Designer, under Sites tab select “Site Options” (see screen below)
3. Find “SaveSiteAsTemplateEnabled” in Site Properties (see below).
4. Next change this setting to “true”.
Apply the Setting once done.
5. Now in your Publishing site navigate to “http://sitename/_layouts/15/savetmpl.aspx” and you would see the old Save Site as Template Page as expected.


How to Save Site as Template in SharePoint 2013
In SharePoint 2013 Sites are Saved as Template in the same way as in earlier versions but there are some steps that you need to consider before moving forward.
Important things to know about Saving Sites as Template –
- In SharePoint 2013, by default, you Cannot Save a Publishing Site (or a Site with Publishing feature activated) as a Site Template.This however Can be done using a workaround (i.e. using _layouts/savetmpl.aspx url). See this detailed post onHow to Save Publishing Site as Template in SharePoint 2013
- As in SharePoint 2010 Saving Sites as Template does not generate a .stp file, it gets saved as a .wsp in Solutions gallery.
- When Saving a Site as Template the WSP generated is temporarily saved in thec:\temp or in c:\windows\tempfolder and later in the solution gallery on SharePoint. Make sure that the App pool account has Full permissions toc:\tempand c:\windows\temp folder.
- You Cannot Create a Subsite based on a Site Template that was Created in SharePoint 2010. You will need to recreate the site template in the 2013.
So here is the Step-by-Step process to Save a Site as Template in SharePoint 2013.
Steps –
1. Open a Team Site that you need to Save as Template and Navigate to Site Settings ->Under “Site Actions” select “Save Site as Template”.
If you do not see Save Site as Template and you get “The “Save site as template” action is not supported on this site.” See this post How to Save Publishing Site as Template in SharePoint 2013
2. Next in the Save as Template Page enter Template Name and Description.Click Ok.
3. Next, you would see a Operation Successful message with a link to “solutions gallery”.
4. If you Navigate to the solutions gallery you can see that the CustomTemplate is added to the library.Next we will create a site using this Template.
5. To Create a Site\Subsite from a Template Navigate to “Site Contents” -> new subsite (towards the bottom).
The New “Project Sites” in SharePoint 2013
Summary : The New “Project Sites” in SharePoint 2013,How to Create “Project Sites” in SharePoint 2013,Difference between Project Site and a Team Site.
SharePoint 2013 has new Project Sites Template that provides Out-of-box webparts and pages that facilitate Project Managers and Teams work efficiently. Lets look at the features of this site template.
How to Create a Project Site – To Create a Project site you can use the Out-of-boxProjects template available. Navigate to Site Contents -> new Subsites and select aProjects template.
Once it gets Created you can see that Projects Sites contain Getting Started tiles, a Project Summary\Timeline webpart,a NewsFeed and a Documents webparts.
Project Summary or Timeline WebPart – The Timeline WebPart in project sites is tied to “Tasks” list by default but you can edit the properties of this webpart and select any other task list to show even task list in other site or subsite as well.To add tasks to timeline click on Edit the task list and add items to the the Tasks list.



The Project Summary webpart on the main page gets the Tasks added to it.It also displays the Days left and


There is not much difference between a Project Site and a Team Site but here are few minor ones for our readers reference
Project Sites
* Project Sites has “Project Functionality” Site Feature activate by default.
* A Project Summary WebPart is added to the main page by default.
* Project Sites had “Task” list added to it by default.
Team Sites
* Team Sites has “Wiki Page Home Page” Site Feature activate by default. “Project Functionality” Feature is not active by default.
* Project Summary WebPart or any Timeline webpart can be added to the site.
* Team Sites had “Team Task” list added to it by default.
The object has been updated by another user since it was last fetched.
Sometimes when we are updating Content Types programmatically, we might come across the following exception:
“The object has been updated by another user since it was last fetched”
I got this exception for the following code in my Feature Receiver’s FeatureActivated method:
private SPContentType EnsureContentType(SPWeb web, string contentTypeName) { SPContentType contentType = web.ContentTypes[contentTypeName]; if (contentType == null) { SPContentType parentContentType = web.ContentTypes[SPBuiltInContentTypeId.Item]; contentType = new SPContentType(parentContentType, web.ContentTypes, contentTypeName); contentType = web.ContentTypes.Add(contentType); } contentType.FieldLinks[SPBuiltInFieldId.Title].Hidden = true; contentType.Description = contentTypeName; contentType.Group = "Test"; contentType.Update(); } public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; using (SPWeb web = site.OpenWeb()) { SPContentType contentType = EnsureContentType(web, "My Content Type"); Guid guid = "CBE1FD3E-351B-43B8-94A6-33868300FA6E"; //Some valid Guid if (contentType.FieldLinks[guid] != null) { contentType.FieldLinks.Delete(guid); contentType.Update(true); //This is the line that throws exception } } }
This exception occurs randomly. The same piece of code is working fine in a different place. The only way that I found to fix this problem is to instantiate new SPSite and SPWeb objects, instead of using SPContext.Current.Web or SPWeb from properties object.
So, I changed my code as shown below to get rid of the exception.
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; using (SPWeb web = site.OpenWeb()) { SPContentType contentType = EnsureContentType(web, "My Content Type"); Guid guid = "CBE1FD3E-351B-43B8-94A6-33868300FA6E"; //Some valid Guid //Instantiating new SPSite and SPWeb objects using (SPSite newSite = new SPSite(web.Site.ID)) { using (SPWeb newWeb = newSite.OpenWeb(web.ID)) { contentType = newWeb.ContentTypes[contentType.Id]; if (contentType.FieldLinks[guid] != null) { contentType.FieldLinks.Delete(guid); contentType.Update(true); //No more exceptions } } } } }
Note: You might also face this problem if you are creating/updating Content Types using xml files. There is a Version attribute in your Elements.xml file that needs to be removed to fix the same problem. For more information, you can refer to this blogwhere the problem is explained in detail.
That’s it guys……a small post on a problem that can be a huge pain.
How to Create a Lists and Libraries in SharePoint 2013 the Old way
In SharePoint 2013 the Concept of “Apps” is a little Confusing. Its not your Phone Apps for sure so what is it? In simple words, some of the SharePoint Components like Lists, Libraries,Sandbox or Custom Applications,few Features like Event Receivers(remote) or Field types (based on existing field types) are termed as “Apps”. So now if someone want to say “Add a new List” to SharePoint, they should probably say “Add a List App” to SharePoint instead.
In SharePoint 2013 you can add a new List using the new “Add an app” option or you can directly switch to the old Create View that you had in SharePoint 2010.Lets see the Old way first
Create a SharePoint 2013 List From Create Page(Old way)
In your Browser Open the URL“https://siteUrl/_layouts/15/create.aspx” to go to the old Create View.
Select Custom List to Create a new List.
Create List with Add an app –
How to get team site lists and templates in SharePoint 2013 publishing site
Team site lists and templates like, survey list, announcement list, task list, promoted links list won’t be available by default for a SharePoint 2013 publishing Site. To enable these list templates and functionalities in SharePoint 2013 publishing site, navigate to site settings, and select Manage Site Features available under “Site Actions” category. Locate the “Team Collaboration Lists” feature is the list of available features and activate it. This will include all the list templates related to team site to a SharePoint Site
Subscribe to:
Posts (Atom)