Monday, May 18, 2015

Check/Validate Date Format in JavaScript

Check/Validate Date Format in JavaScript
function checkDateFormate() {

            var date1 = $('#<%= date1.ClientID %>').val();
            var date2 = $('#<%= date2.ClientID %>').val();
            var date3 = $('#<%= date3.ClientID %>').val();
            var date4 = $('#<%= date4.ClientID %>').val();

          var arrayDates = ["date1", date1, "date2", date2, "date3", date3, "date4", date4];

            var var_return = false;
            var validformat = /^\d{2}\/\d{2}\/\d{4}$/
            var errorMsg1 = "";
            var errorMsg2 = "";
            var errorMsg3 = "";
            var dateVal = "";

            for (var i = 1; i < arrayDates.length; i = i + 2) {
                dateVal = arrayDates[i]; 
                if (dateVal != "") {
                    if (dateVal.length > 0) {
                        if (!validformat.test(dateVal)) {
         //alert("Invalid Date Format. Please correct and save/submit again (mm/dd/yyyy).");
                            errorMsg1 += '\n\u2022  ' + arrayDates[i - 1];
                            alert(errorMsg1);
                        }
                        else {
                            var monthfield = dateVal.split("/")[0]
                            var dayfield = dateVal.split("/")[1]
                            var yearfield = dateVal.split("/")[2]

                            var obj_Date = new Date(yearfield, monthfield - 1, dayfield)
                            obj_Date.setHours(0);
                            obj_Date.setMinutes(0);
                            obj_Date.setSeconds(0);

                            var todayDate = new Date();
                            todayDate.setHours(0);
                            todayDate.setMinutes(0);
                            todayDate.setSeconds(0);

                            if ((obj_Date.getMonth() + 1 != monthfield) || (obj_Date.getDate() != dayfield) || (obj_Date.getFullYear() != yearfield)) {
//alert("Invalid Day, Month, or Year range detected. Please correct and submit again (mm/dd/yyyy).");
                                errorMsg2 += '\n\u2022  ' + arrayDates[i - 1];
                                alert(arrayDates[i - 1]);
                            }
                            else {
                                var_return = true;
                                //if (Date.parse(obj_Date) < Date.parse(todayDate)) {
                       //    alert("Selected Date should be greater than or equal to Today.")
                                //}
                                //else {                               
                                //     var_return = true;
                                // }
                            }
                        }
                    }
                }
                //else {
                //    alert("Please enter Date.");
                //}
            }

            if (errorMsg1.length > 0 || errorMsg2.length > 0) {
                if (errorMsg1.length > 0 && errorMsg2.length > 0) {
                    alert('Invalid Date Format. Please correct and save/submit again (mm/dd/yyyy).' + errorMsg1 + '\n\n' + 'Invalid Day, Month, or Year range detected. Please correct and submit again (mm/dd/yyyy).' + errorMsg2);
                }
                else if (errorMsg1.length > 0) {
                    alert('Invalid Date Format. Please correct and save/submit again (mm/dd/yyyy).' + errorMsg1);
                } else if (errorMsg2.length > 0) {
                    alert('Invalid Day, Month, or Year range detected. Please correct and submit again (mm/dd/yyyy).' + errorMsg2);
                }
            }
            //if (errorMsg3.length > 0) {
            //    alert(errorMsg3);
            //}
            return var_return;
        }

Thursday, May 7, 2015

Invalid data has been used to update the list item. The field you are trying to update may be read only | The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested

Issue1: Invalid data has been used to update the list item. The field you are trying to update may be read only.

Issue2: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

Problem Code:
internal static Void GetFileFromTempDocLib(ClientContext clientContext1)  
{
                var folderRelativeUrl = "";
                Web web = clientContext.Web;                
                clientContext.Load(web, w1 => w1.ServerRelativeUrl, w1 => w1.Url);
                clientContext.ExecuteQuery();
                folderRelativeUrl = web.ServerRelativeUrl;

}

Solution Code:
internal static Void GetFileFromTempDocLib(ClientContext clientContext1)  
{
                var folderRelativeUrl = "";
                Web web = clientContext.Web;
                try
                {
                    folderRelativeUrl = web.ServerRelativeUrl;
                }
                catch (PropertyOrFieldNotInitializedException ex)
                {
                    clientContext.Load(web, w1 => w1.ServerRelativeUrl, w1 => w1.Url);
                    clientContext.ExecuteQuery();
                    folderRelativeUrl = web.ServerRelativeUrl;
                }
}

Error occurred in deployment step 'Install app for SharePoint': Failed to install app for SharePoint. Please see the output window for details.

"Error occurred in deployment step 'Install app for SharePoint': Failed to install app for SharePoint. Please see the output window for details."

There are many reasons to get this error message..
In my case this is the reason..

if we are working with "Manage NuGet Packages.." some times a config file namely "App.Config" will be add into our solution.

This is the App.Config File

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IdentityModel" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ServiceModel" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

Solution1:-
1. "App.Config" => right click => deployment type ="NoDeployment" and try to deploy.

Solution2:-
2. So delete this App.Config and try to deploy again. our will be deploy successfully.