Created
December 26, 2016 14:53
-
-
Save durgesh97025/9eed8a4c7427d7927c509cc3b585a364 to your computer and use it in GitHub Desktop.
How to Call Ajax Function in PreSaveAction without any dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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