Skip to content

Instantly share code, notes, and snippets.

@durgesh97025
Created December 26, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durgesh97025/9eed8a4c7427d7927c509cc3b585a364 to your computer and use it in GitHub Desktop.
Save durgesh97025/9eed8a4c7427d7927c509cc3b585a364 to your computer and use it in GitHub Desktop.
How to Call Ajax Function in PreSaveAction without any dependencies
var G_IsUpdatePending = true;
function PreSaveAction(){
AssignQuarter();
if (G_IsUpdatePending){
var dutyStation = GetSelectedTermText('Office')
if (dutyStation){
ShowDialog();
$.when(AddCountryToField('Office','Country_','Region_')).then(function(){
G_IsUpdatePending = false;
HideDialog();
SubmitForm();
});
returnValue = false;
}
else{
returnValue = true;
}
}
else{
G_IsUpdatePending = true;
returnValue = true;
}
return returnValue;
}
function SubmitForm(){
if ($("INPUT[value='Save']").length > 0){
$("INPUT[value='Save']").first().click();
}
else{
$("INPUT[value='Check In']").first().click();
}
}
function GetSelectedTermText(fieldName){
var selectedTerm = document.getElementById(fieldName+"_$input").value;
if (selectedTerm && selectedTerm != "") {
selectedTerm = selectedTerm.split('|')[0];
}
return selectedTerm;
}
function AssignQuarter(){
var currentMonth = $.GetFieldControl("Month").val();
var qValue = "";
if (currentMonth == "January" || currentMonth == "February" || currentMonth == "March"){
qValue = "Q1";
}
else if (currentMonth == "April" || currentMonth == "May" || currentMonth == "June"){
qValue = "Q2";
}
else if (currentMonth == "July" || currentMonth == "August" || currentMonth == "September"){
qValue = "Q3";
}
else if (currentMonth == "October" || currentMonth == "November" || currentMonth == "December"){
qValue = "Q4";
}
$.GetFieldControl("Quarter Required Field").val(qValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment