Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I save a record before another function?

KennethBlacow
Collaborator II

Hello All,

 

I have implemented Jason Solar's Prev-Next tab code Toggle Tab Controls (previous,next), but I would like to save the record before the tab switcher runs. I can get the record to save, then switch tabs, but then the page reloads and it goes back to the default tab. I am guessing I need to learn how to use David Petty‌'s suggested Windows sessionStorage Property, but I do not understand javascript enough to make those changes. Anyone that can help me would be greatly appreciated.

 

Ken

11 REPLIES 11

Thanks, David that moved me forward, but now we are getting a script error Unable to get property 'click' of undefined or null reference. for the following line of code.

 

tabStrip.get_tabs().getTab(sessionStorage.getItem("tabIndex")).click();

 

I wish I knew more java to troubleshoot myself, but I am just don't understand enough. I did figure out the first issue last night, but I started getting this new error, so I figured I had put a curly brace or closing parentheses in the wrong place. 

KennethBlacow
Collaborator II

David Petty

Hi David,

 

I have the following code working it advances the tab at the same time it saves the record. However, I get the next tab on the screen, then when the master_btnApply function animation shows Loading it goes back to the tab I just left. 

<script type="text/javascript">  
var tabIndexes, tabSetId, selectedTabIndex, tabStripElementId, tabStrip;
Sys.Application.add_load(function() {
$.each($LM._tabSets, function(key, value) {
tabSetId = key;
});

if (tabSetId) {
tabIndexes = $LM._tabSets[tabSetId].tabIds;
tabStripElementId = 'master_DefaultContent_rts_ts' + tabSetId + '_t';
tabStrip = $find(tabStripElementId);
selectedTabIndex = tabStrip._selectedIndex;

// Hide previous button if users is on the first tab
if (selectedTabIndex == 0) $('.btnprev').hide();

// Hide next button if users is on the last tab
if (selectedTabIndex == 3) $('.btnnext').hide();
}
if (sessionStorage["tabIndex"]) {
tabStrip.get_tabs().getTab(sessionStorage.getItem("tabIndex"));
sessionStorage.removeItem("tabIndex");
}
});

function selectTab(action) {
var tabId, tab;
if (action == 'prev') {
sessionStorage.setItem("tabIndex", tabIndexes[selectedTabIndex-1]);
tabId = sessionStorage.getItem("tabIndex");
tab = $('li.tab_'+tabId).find('a.rtsLink').trigger('click');
tab.find('span.rtsTxt').trigger('click');
$('#master_btnApply').click(); //Added by Ken to Save record first
}

if (action == 'next') {
sessionStorage.setItem("tabIndex", tabIndexes[selectedTabIndex+1]);
tabId = sessionStorage.getItem("tabIndex");
tab = $('li.tab_'+tabId).find('a.rtsLink').trigger('click');
tab.find('span.rtsTxt').trigger('click');
$('#master_btnApply').click(); //Added by Ken to Save record first
}

console.log(tabIndexes, selectedTabIndex, tabId, tab);

}
</script>

 Scratching my head!!