Repeating Table – set color for alternative rows and auto number the rows


Set color for alternative rows:

Logic behind : Odd number of rows(1,3,5,7..) when divided by 2 will return the remainder 1  and even number of rows(2,4,6,8..) when divided by 2 will return the remainder 0. To find the remainder, we use mod(modulo) operator. To find whether the row is odd number or even number, we can use position() in infopath.

  • Go to Home->Manage rules
  • In fields pane, select the group containing repeating fields and add formatting rule
  • Under condition, click on None and select “The expression” in first drop down
  • To color the odd rows, enter the expression as position() mod 2 > 0 or position() mod 2 = 1
  • Under Formatting, select the color that you would like to apply in Shading(bucket symbol)

Color alternative rows

  • Click on Home->Preview to see the result

Auto number repeating table rows:

  • To auto generate number in SNO inside repeating table, right click on SNO ->Text Box Properties
  • Under Default values, click on fx and insert the formula, count(../preceding-sibling::my:group2) + 1 and click ok

  • You can also use position() instead of the above formula but this will not be supported in InfoPath 2013 text box. However, it can be used in Calculated value in InfoPath 2013. Right click the SNO ->Change Control->Calculated Value and enter position() in XPath

  • Click on Home -> Preview to see the result.

 

Advertisements

Repeating Table – Set default number of rows and limit the total number of rows


Repeating table plays a vital role in form library to insert several rows of data in a single form. In this post, let’s see two different methods of setting the default number of rows and limiting the total number of rows in repeating table.

METHOD 1 – Using Default Values and Rules

Set default number of rows:

  • Go to Data tab in the ribbon and click on Default Values
  • In Edit Default values dialog box, right click on group that contains the repeating table fields and select “Add another group below”. Repeat this step to increase the default number of rows
  • Click on Home->Preview to see the result.

  • Limitation – You will not be able to remove the rows inserted by this method

Limit total number of rows:

  • Go to Home tab and click on Manage rules
  • Select the group(group2 in above picture) that contains repeating fields in Fields pane
  • In Rules pane, click on New -> Formatting
  • Under condition, select “The expression” in first drop down, type the expression value as count(/my:myFields/my:group1/my:group2) = 6
  • Under Formatting, tick the box “Don’t allow users to insert or delete this control” as depicted below

  • Now, when the user inserts the 6th row and click on insert item, rows will not be created and drop down highlighted below shown till 5th row will disappear on inserting 6th row to prevent insertion and deletion.

METHOD 2: (Modifying the Source File)

  • After designing the form with repeating table, click on Publish -> Export Source Files

  • Browse the location and type the folder name to save the source file

  • Close the InfoPath form and open “myschema.xsd” from source file folder

  • To set default number of rows, change the minOccurs value as shown below
  • To limit the total number of rows, change the maxOccurs value as shown below

  • Save myschema.xsd and close it
  • Open manifest file in Design mode, preview and publish it
  • Now, when the user tries to insert 11th row, below error will be shown.

How to find Created Date and Size of a Subsite in SharePoint


In this article, let us see how to find when a subsite is created and what is the size of the subsite in SharePoint

Steps:

  • Go to a document library in subsite (or top level site) and click on “Open with Explorer as shown below

Open with Explorer

  • This will open the explorer window with subsite library contents as shown below. Click on the top site name(in my case, MngsvcsCollab) to show the top site contents.

Sub site in Explorer window

  • Right click on subsite for which you want to find the Created Date and Size and click on Properties

Top site contents

  • In Properties window, you can see the size of subsite as 34.8 MB and Created as June 22,2017.

Sub site Properties

That’s it. This method can also be used to find when a list or library is created and size of it in SharePoint.

Hide items after 90 days without using workflows


We always prefer “Pause until Date” in SharePoint Designer workflow to delete the items or to hide the items after 90 days. In this post, I will show you how to hide the items without using SharePoint designer workflow.

  • Create a Calculated column in list (Say, Is90days) with the formula, =Created+90 with Date as return type as shown below

  • Create a standard view called, Myview with the below filters
    • CreatedBy=[Me] to show only their items.
    • Is90days>=[Today] to show the items only till 90 days from the creation date.

 

NOTE: If you have sensitive data and you are afraid that they might switch the view to see all the items, you may target the audience for the list web part with all the items.

How to check-in multiple files at once


SCENARIO:

When you have a mandatory column in document library and when you upload multiple files and folders in it using “Open with explorer” option, all the files either within or without folders will be checked out by default.

Checked Out Files

When you try to check-in the file, it will prompt you to fill out all the required properties before checking in the file.

SOLUTION:

How to fill out the properties for multiple files(including the files within folders):

  • Click on Library in the ribbon and click “Create View” under Manage Views
  • Choose Datasheet view, give a name(say, Properties view) and check the boxes under Columns for Type, Name and the mandatory columns
  • Expand the folder and choose “Show all items without folders”and click OK button.

Folder Options

  • Now, fill out the values for mandatory column in properties view

Properties View

  • Stop editing this list

How to Check-in the files:

  • Go to Properties view and switch to Standard view
  • Select all the documents using ‘Tick Mark” behind Name column
  • Click on Files tab in the ribbon and select “Check In” under “Open & Check Out”

Check In.png

Alternative ways to check in multiple files in Publishing sites:

If you have at least edit permission in a publishing site, you can use the below method:

  • Go to Site Settings and click on “Content and Structure” under Site Administration
  • Change the view from “Default View” to “Checked Out To Me” as depicted below:

Content and Structure - Checked Out to Me.png

  • Select all the documents, go to Actions and select “Check In” as shown below

Content and Structure - Check In.png

That’s it!

SharePoint REST API results in browsers


Rest api results for SharePoint lists can be seen in Google Chrome in xml format.

What if you don’t have Chrome and still interested in viewing results ?

To view results in IE:

Feed in IE

  • Go to Settings and click on Internet Options

IE options

  • Click on Settings under Feeds and Web Slices in Content tab and uncheck the turn on feed reading view box.

Settings

  • You will see the results in Xml format as shown below:

xml

To view results in Mozilla Firefox:

  • Open Firefox and type the rest url. You will see the same feeds page as IE

Firefox feed

Result in firefox

Advantages of viewing results in browsers:

  • You can immediately verify the rest operation results
  • You can find the column name to use it in rest operation

Exclude AllItems.aspx from Search Results in Content Search Web Part


When I was working with Content Search web part in one of my SharePoint sites, I experienced a problem where the search result for list items is displayed along with list views.
In this article, I will show you how to remove the list views in CSWP search results.
For better understanding, consider a list, EMPINFO from which you want to show the items in CSWP. To show specific list items, you might have carried out the below steps

  • Edit the CSWP and click on Change query

  • Choose Documents (System) in Select a query
  •  Choose Specify a URL and enter the list URL for Restrict by app

  • Switch to Advanced mode and remove the highlighted file extension query text.

  • You can see AllItems.aspx view along with the list items in search results.

To remove the view, you can follow any one of the below step:

  • Select “Only return items “ in keyword filter and click on “Add Keyword Filter”
  •  Just append [contentclass:STS_ListItem] after Path in Query text

Upgrading SharePoint App


Whenever you make changes and redeploy the app, data that were created previously by the app will be lost. To make changes in the app without losing the data, you need to upgrade the app.

Let us see how to upgrade the app:

  • Open AppManifest.xml and increment the version number by 1 whenever a change is made
  • In my case, version is 1.0.0.2. Hence I am changing it to 1.0.0.3 and publishing the app as shown below:

Publishing app

  • Click on Finish in Publish summary.

Publish summary

  • Explorer window opens as depicted below:

Published app version

  • Copy the location of the file and go to the developer site
  • You can see the list of apps in App Testing. Select the app and click on upgrade an app

Upgrade

  • Click on Upload and browse the file from copied location

Upgrade - Upload

  • Click on Upgrade

Upgrad - Complete

  • You can see the upgrade progress as shown below:

Upgradeinprogress

  • Once upgraded, the version is changed to 1.0.0.3 and if you check for the previous data, it actually exists.

That’s it!

Reference: http://www.c-sharpcorner.com/article/upgrade-sharepoint-hosted-add-insapps-in-sharepoint-2013/

 

PART 2 : SharePoint-Hosted App


Have you read PART 1? Cool. Continue reading how to create an app in host web.

Let us see the same create operation for better understanding. We need two URLS for this:

  • HostURL
  • AppWebURL

To retrieve the URLS, QueryStringParameter() is generally used. But this does not work in all the cases especially when we move from one page to another in app web. So, let’s use the below one:

  • appWebUrl = window.location.protocol+”//”+window.location.host+_spPageContextInfo.webServerRelativeUrl;
  • hostUrl = _spPageContextInfo.siteAbsoluteUrl;

To change the context site from app web to other sites, AppContextSite() is used. To change the current context(i.e, app web) to host web, pass it as
var appctx = new SP.AppContextSite(ctx, hostUrl);

Let’s combine all these with previous code. Here you go:

var appWebUrl;
var hostUrl;
$(document).ready(function ()
 {
appWebUrl = window.location.protocol+"//"+window.location.host+_spPageContextInfo.webServerRelativeUrl;
hostUrl = _spPageContextInfo.siteAbsoluteUrl;
 $("#create").on('click', function ()
 {
                createList();
  });
});
//create List
function createList()
 {
    var listTitle = $("#listName").val();
    var ctx = new SP.ClientContext(appWebUrl);
    var appctx = new SP.AppContextSite(ctx, hostUrl);
    var oweb = appctx.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(listTitle);
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
    oweb.get_lists().add(listCreationInfo);
    ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() 
{
    alert("List Created");
}
function onQueryFailed(sender, args) {
    alert("Operation Failed" +"\n"+ args.get_message());
}

After deploying the app, when you create the list, the below error is shown

Access Denied for Host Web

  • This is because to access or create resource in host web, we need to give FULL CONTROL permission for web and list. To give permission, open AppManifest.xml, move to permission tab and give the permission as shown below:

Fullconrol Permission

  • Now when you deploy it, you will get the below page:

Trust the app

  • Click on trust and create a list using the app. List is created in the host web and can be seen in the site contents page.

If you have noted that when you deployed the app again after making some changes, the data created previously were lost. Continue reading the next article, Upgrading SharePoint app to learn how to deploy the app without losing the data.

PART 1: SharePoint-Hosted App


Apps for SharePoint are also called as SharePoint Add-ins. In SharePoint 2013, everything is considered as an app. Lists, libraries are all called as apps. Apps can be hosted

  • In SharePoint farm (SharePoint-hosted)
  • In separate server(Provider-hosted)
  • In cloud(Auto-hosted)

SharePoint-Hosted App:

It includes only SharePoint components. SharePoint Site where the app is installed is called Host web. All the resources such as list, libraries are in isolated sub site called App web.

Let us create a SharePoint-hosted app to create a list in SharePoint On-Premise environment.

  • Run Visual Studio as administrator and click on File->New->Project

New Project

  • Select Apps for SharePoint 2013 and give a name(say, createListinHost) and hit ok button

Host

  • Next, Specify the site url ( say,Developer site), select the type as SharePoint Hosted and click on Finish

SharePoint Hosted app

  • App is created and default aspx page is shown.

Default aspx

  • Replace the highlighted code with the below one to create a textbox and button for create operation.

<label for=”listName”>List Name to be created</label>
<input type=”text” id=”listName” Placeholder=”Enter the listname”/>
<input type=”button” id=”create” value=”Create”/>

  • Branding(Optional):
    • You can change the title of the page in
      <asp:Content ContentPlaceHolderID=”PlaceHolderPageTitleInTitleArea” runat=”server”> List Creation </asp:Content
    • You change the icon for app in AppManifest.xml. Open AppManifest and change the image for Icon. Image should be of 96*96 pixel

App Icon

  • To insert create functionality in this app, expand Scripts, open App.js and insert the below code:
$(document).ready(function () 
{ 
    $("#create").on('click', function () {
                createList();
    });
});
//create List
function createList()
{
    var listTitle = $("#listName").val();
    var ctx = SP.ClientContext.get_current();
    var oweb = ctx.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title(listTitle);
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
    oweb.get_lists().add(listCreationInfo);
    ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() {
    alert("List Created");
}
function onQueryFailed(sender, args) {
    alert("Operation Failed" +"\n"+ args.get_message());
}
  • Press F5 or click on Solution->Deploy to deploy the code. Default aspx page will be opened in browser. If not go to the site->Site Contents and click on the app, “createListinHost”

App in Site Contents

  • Create a list say, Sample

 

Below page is shown where you can see that sample list created under “createListinHost”

Sample list settings

Site lists and libraries

Now, question arises. Should all the resources reside in app web only? What If I need to create a resource or access a resource that is in host web? Can I do it? Yes, you can create and access resources in host web. Continue Reading in PART 2