Tuesday, April 11, 2017

Change the "Source" redirection of SharePoint New and Edit forms on Save and Cancel

On document.ready put this code:-

    var button = $("input[id$=SaveItem]");
    // change redirection behavior
    button.removeAttr("onclick");
    button.click(function() {
        var elementName = $(this).attr("name");
        var aspForm = $("form[id=aspnetForm]");
        var oldPostbackUrl = aspForm.get(0).action;
        var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
        var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "https%3A%2F%2Fint%2Eapac%2Esp%2Ewp%2Ecorpintra%2Enet%2Fsites%2F04400%2FDashboard%2520UAT%2FSitePages%2FProjects%2Easpx");

        if (!PreSaveItem()) return false;
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));

    });

Monday, April 10, 2017

2 level Cascading Lookup using SP Services

Pre-requisites :

  • JQuery Reference
  • SP Services Reference
Code :


<script type="text/javascript" src="../../SiteAssets/Scripts/jquery.2.1.3.min.js"></script>
<script type="text/javascript" src="../../SiteAssets/Scripts/jquery.SPServices-2014.02.js"></script>  
<script type="text/javascript">  
$(document).ready(function ()  
{  
$().SPServices.SPCascadeDropdowns({
  relationshipWebURL: "",
  relationshipList: "StateList",
  relationshipListParentColumn: "LookupCountry",
  relationshipListChildColumn: "State",
  parentColumn: "LookupCountryParent",
  childColumn: "LookupStateParent",
  debug: false
});
$().SPServices.SPCascadeDropdowns({
  relationshipWebURL: "",
  relationshipList: "CityList",
  relationshipListParentColumn: "LookupState",
  relationshipListChildColumn: "City",
  parentColumn: "LookupStateParent",
  childColumn: "LookupCityParent",
  debug: false
});

});
</script>

Explanations:-

  1. relationshipList - The list which has parent/child relationship.
  2. relationshipListParentColumn - The lookup column in relationshipList.
  3. relationshipListChildColumn - The column which is dependent on relationshipListParentColumn.
  4. parentColumn - The lookup column in parent list/master.
  5. childColumn - The lookup column in parent list/master list.
Analogy:-

CountryList

Title

India
UK
US

StateList

State LookupCountry

MP              India
Karnataka   India


CityList

City             LookupState

Bangalore    Karnataka
Ujjain          MP

ParentList - This is the list where I want cascading lookups i.e. on change of Country respective State should come, and further city should load for respective states.

Title      LookupCountryParent     LookupStateParent     LookupCityParent

New      India                                    Karnataka                      Bangalore

Clearing Person/Group Values

To clear out or empty the values in person or group columns, how you do it depends on if the column is single-value or multi-value. For ...