0

While working on customizing the Share-point Site we have used Share-point Hosted App Model. There is an issue that I am currently facing on when using App Model.

Following are the steps I have done.

  1. Created an Share-point Hosted App Model using Visual Studio.
  2. When the app is created there are in-built files named as App.js and default.aspx
  3. The code in App.js file will get the current context and display the current login person name inside a p tag present in default.aspx
  4. At this point I am getting the username and I can see it inside the p tag.
  5. In the default.aspx I have added controls such as text-area, button, text-box and build was succeeded and I deployed the solution.
  6. Now in my share-point site, I created a new page and added the App-part, but is not displaying in my page. Its showing as

enter image description here

Code in

AppManifest file

<AppPrincipal>
<Internal/>
</AppPrincipal>
<AppPermissionRequests AllowAppOnlyPolicy="false">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="Manage" />
</AppPermissionRequests>

Default.aspx

 <%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" MasterPageFile="~masterurl/default.master" Language="C#" %>

    <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <%-- The markup and script in the following Content element will be placed in the <head> of the page --%>
    <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
        <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
        <SharePoint:ScriptLink name="sp.js" runat="server" OnDemand="true" LoadAfterUI="true" Localizable="false" />
        <meta name="WebPartPageExpansion" content="full" />

        <!-- Add your CSS styles to the following file -->
        <link rel="Stylesheet" type="text/css" href="../Content/App.css" />

        <!-- Add your JavaScript to the following file -->
        <script type="text/javascript" src="../Scripts/App.js"></script>
    </asp:Content>

    <%-- The markup in the following Content element will be placed in the TitleArea of the page --%>
    <asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
        Page Title
    </asp:Content>

    <%-- The markup and script in the following Content element will be placed in the <body> of the page --%>
    <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">

        <div>
            <p id="message">
                <!-- The following content will be replaced with the user name when you run the app - see App.js -->
                initializing...
            </p>
    <input type="text" id="txtApprove" name="txtApprove"/>
    <input type="button" value="Approve" id="btnApprove" name="btnApprove"/>
        </div>

    </asp:Content>

App.js

'use strict';

ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");

function initializePage()
{
    var context = new SP.ClientContext("/sites/sitename");
    var user = context.get_web().get_currentUser();
    var oListItem;
    // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
    $(document).ready(function () {        
        getUserName();
        UpdateWFStatusColumn(58);
    });

    // This function prepares, loads, and then executes a SharePoint query to get the current users information
    function getUserName() {
        context.load(user);
        context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
    }

    // This function is executed if the above call is successful
    // It replaces the contents of the 'message' element with the user name
    function onGetUserNameSuccess() {
        $('#message').text('Hello ' + user.get_title());
    }

    // This function is executed if the above call fails
    function onGetUserNameFail(sender, args) {
        alert('Failed to get user name. Error:' + args.get_message());
    }

    function UpdateWFStatusColumn(itemId) {
        var web = context.get_web();
        var oList = web.get_lists().getByTitle('EmpList');
        oListItem = oList.getItemById(itemId);
        oListItem.set_item('ApprovalStages', 'Approval');
        oListItem.update();
        context.load(oListItem);
        context.executeQueryAsync(
            function (sender, args) {
                alert("Workflow started");
            },
            function (sender, args) {
                alert("Failed to load subscription.");
                alert("Error: " + args.get_message() + "\n" + args.get_stackTrace());
            }
            );
    }
}
2
  • You are adding app-part.. Have you created Client Webpart ? Commented Jun 3, 2016 at 11:33
  • Yes. I have created app Model and but not Client Webpart Commented Jun 6, 2016 at 6:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.