Tuesday, November 1, 2016

sharepoint column color coding based on field values and nowrap for long values


<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){


$("td.ms-cellstyle.ms-vb2").filter( function (index) {  return $(this).text() == "Assigned to Commander";})
    .css("color", "lightpurple").css("font-weight", "bold").css("white-space","nowrap");

   
   

$("td.ms-cellstyle.ms-vb2").filter( function (index) {return $(this).text() == "Assigned to Bureau";})
    .css("color", "#a2aa0b").css("font-weight", "bold").css("white-space","nowrap");
   
   
     
$("td.ms-cellstyle.ms-vb2").filter( function (index) {return $(this).text() == "Assigned to Investigating Member";})
    .css("color", "#85aa0b").css("font-weight", "bold").css("white-space","nowrap");
   
         
$("td.ms-cellstyle.ms-vb2").filter( function (index) {return $(this).text() == "Sent for Approval";})
    .css("color", "#6baa0b").css("font-weight", "bold").css("white-space","nowrap");
   
   
$("td.ms-cellstyle.ms-vb2").filter( function (index) {return $(this).text() == "Approved For System Update";})
    .css("color", "#4a8bd6").css("font-weight", "bold").css("white-space","nowrap");
   

$("td.ms-cellstyle.ms-vb2").filter( function (index) {return $(this).text() == "Approved";})
    .css("color", "#226d04").css("font-weight", "bold").css("white-space","nowrap");
   

$Text = $("td.ms-cellstyle.ms-vb2:contains('Rejected')");
$Text.css("color", "#fc7735");
$Text.css("font-weight", "bold");

Tuesday, June 28, 2016

Web Part That Can Read and Write Data to an External Data Source Using BCS sharepoint 2013

CODE behind:

using System;
using System.Drawing;
using System.Web.UI;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;

using Microsoft.BusinessData.Infrastructure;
using Microsoft.BusinessData.MetadataModel.Collections;

namespace spvwp.CommanderWebPart
{
    public partial class CommanderWebPartUserControl : UserControl
    {
        #region Properties

        //protected string EntityNamespace
        //{
        //    get { return ECTNamespace.Text.Trim(); }
        //}

        //protected string EntityName
        //{
        //    get { return ECTName.Text.Trim(); }
        //}

        //protected bool EntityValuesAreSet
        //{
        //    get
        //    {
        //        if (EntityNamespace == string.Empty ||
        //          EntityName == string.Empty)
        //            return false;
        //        else
        //            return true;
        //    }
        //}

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btncreate_Click(object sender, EventArgs e)
        {
            try
          {

            using (new Microsoft.SharePoint.SPServiceContextScope(SPServiceContext.GetContext(SPContext.Current.Site)))
            {
                // Get the BDC service and metadata catalog.
                BdcService service = SPFarm.Local.Services.GetValue<BdcService>();
                IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);

                // Get the entity by using the specified name and namespace.
                IEntity entity = catalog.GetEntity("<entity namespace>", "<entity name>");
                ILobSystemInstance LobSystemInstance = entity.GetLobSystem().GetLobSystemInstances()[0].Value;

                IView createview = entity.GetCreatorView("Create");
                IFieldValueDictionary valueDictionary = createview.GetDefaultValues();

                // Set the values of the entity fields.

                valueDictionary["CommanderName"] = txtCommanderName.Text;


                // Call the creator method and display the returned
                // Customer ID.
                Identity id = entity.Create(valueDictionary, LobSystemInstance);

                CommanderID.Text = id.GetIdentifierValues().GetValue(0).ToString();

                StatusLabel.ForeColor = Color.Green;
                StatusLabel.Text = "Commander added successfully With ID: " + CommanderID.Text;

            }
          }
            catch (Exception ex)
            {
                StatusLabel.ForeColor = Color.Red;
                StatusLabel.Text = "Unable to create Commander." +
                  ex.Message;
            }

        }
    }
}


Webpart After Deployed to SharePoint 2013:


Friday, March 25, 2016

jquery fileupload validation , allowing only specific file extensions

  $("#FileUploadToServer").change(function () {
           
        //    var fileExtension = [ 'jpg', 'png', 'pdf'];
        //    if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
        //        alert("Only formats are allowed : " + fileExtension.join(', '));
        //        $('#FileUploadToServer').val('');
        //    }
        //});