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

Ilya_Khen
Champion III

Kenneth Blacow,

 

There was a nice discussion with David Petty which can help:

Sub-Forms and Last Updated 

 

Also, this could be useful:

Custom Object Code Button - Page Redirect 

DavidPetty
Archer Employee
Archer Employee

Normally Archer shouldn't be defaulting back to the default tab when saving a record.  How are you calling the save?

 Advisory Consultant - Archer, an RSA Business

I tried two different ways, first in the script itself. This code is from @jason solar

<script type="text/javascript">

var tabIndexes, tabSetId, selectedTabIndex;
function pageLoad() {
$.each($LM._tabSets, function(key, value) {
tabSetId = key;
});

if (tabSetId) {
tabIndexes = $LM._tabSets[tabSetId].tabIds;
var tabStripElementId = 'master_DefaultContent_rts_ts' + tabSetId + '_t';
var 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();
}
}

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

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

}
}
</script> ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then I tried it in the HTML, again this code came from Jason's solution.

<table border='0' style='width: 100%'>  
<tr>
<td style='width: 50%; text-align:left; padding: 10px;'>
<img class="btnprev"

src="../BackgroundImageGenerator.axd?className=StyledButton&classProperties=caption:Previous+Module;iconSetStyle:VistaRound;baseColor:%23DDDDDD;disabled:False"

onclick="$('#master_btnApply').click();selectTab('prev')"
/>

</td>
<td style='width: 50%; text-align:right; padding: 10px;'>
<img class="btnnext" src="../BackgroundImageGenerator.axd?className=StyledButton&classProperties=caption:Next+Module;iconSetStyle:VistaRound;baseColor:%23DDDDDD;disabled:False"

onclick="$('#master_btnApply').click();selectTab('next')"
/>

</td>
</tr>
</table>

Thanks, the issue is that the save is "dumping" the page along with the next call selectTab.  You'd need to store the the tab index before you save the page to recall it when the page loads.

 

Something like this:

<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")).click();
sessionStorage.removeItem("tabIndex");
}
});


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

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

}
}
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant - Archer, an RSA Business

Thank you David Petty‌ and Ilya Khen‌ I had to move on to something else, but I will test this out and post the results.

 

Ken

KennethBlacow
Collaborator II

I finally figured out this mention thing. Thanks go out to Jason Solar‌ for the code snippet he originally shared.

I'm getting an error on the page shown in the screen cap.

pastedImage_1.png

Sys.Application.add_load does not require function declaration. Also, you need to write it as:

Sys.Application.add_load(function() {

 

});

My bad, copying and pasting

 

I've updated my post with the correction.

 Advisory Consultant - Archer, an RSA Business