On my SharePoint calendar I have a choice field called "status". The default value for this field is 'Pending Approval' and that needs to remain the default value.
I would like to update the status to "Approved" when an event is added through the default New Form in the calendar view. I already have a script which updates the "All Day Event" field and I would like to utilize the script to update the status as well if possible. How would I accomplish that? Below is the script I'm currently using.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("ready");
function ready() {
setTimeout(function(){
// checks All Day Event
if (!$('span[title="All Day Event"] > input').attr("checked")) {
$('span[title="All Day Event"] > input').click();
}
//hide check-box
$('tr:has(span[title="All Day Event"])').not('tr:has(tr)').hide();
//$('nobr:contains("All Day Event")').closest('tr').hide();
}, 600);
}
</script>
Try the code snippet below:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(function(){
setTimeout(function(){
// checks All Day Event
if (!$('span[title="All Day Event"] > input').attr("checked")) {
$('span[title="All Day Event"] > input').click();
}
if($('select[title="status"] option:selected').val()!="Approved")
{
$('select[title="status"] option[value=Approved]').attr('selected', 'selected')
}
//hide check-box
$('tr:has(span[title="All Day Event"])').not('tr:has(tr)').hide();
//hide status row if needed
//$('nobr:contains("status")').closest('tr').hide();
}, 600);
});
</script>