Page 1 of 1

Link to record in subform on a tab

Posted: Mon Oct 18, 2021 6:42 pm
by treed
Hello all, I'm building a "to do" list. Right now there is a browse list that shows the Organization and to do item from a related table. The way the current form works is that when the user clicks on the browse record it opens the organization record and the user has to go to the to do tab and find the record in question in the sub form. The way I would like it to work is that clicking on the browse record, the to do item is opened in the subform. Is this possible?

Re: Link to record in subform on a tab

Posted: Tue Oct 19, 2021 9:02 am
by kev1n
treed wrote: The way I would like it to work is that clicking on the browse record, the to do item is opened in the subform. Is this possible?
Would it suffice if the to-do tab is opened and then the record in the subform focused/highlighted?

Re: Link to record in subform on a tab

Posted: Wed Oct 20, 2021 11:38 pm
by treed
That would be perfect!

Re: Link to record in subform on a tab

Posted: Thu Oct 21, 2021 8:11 pm
by kev1n
Add the Primary Key column of the to-do item to the Browse form (column width 0 to hide it).

In the form's Custom Code add this JavaScript code.
Replace some values as indicated in the code

Code: Select all

function nuSelectBrowse(e) {

    let pk = $('#' + e.target.id).attr('data-nu-primary-key');
    let row   = $('#' + e.target.id).attr('data-nu-row');
	
	let pkColumn = '0';  // <------ Change: Column number of the to-do's primary key. 0 = first column, 1 = 2nd column etc.
	
	window.pkToDo   = $('#nucell_' + row + '_' + pkColumn).html();   
	
	nuForm(nuGetProperty('form_id'), pk, '', '', '0');

}


if (nuFormType() == 'edit') {

	if (window.pkToDo !== undefined) {
	
		nuSelectTab($('#nuTab1')[0]);  // <------ Select the 2nd tab. nuTab2 would be the 3rd tab etc.
		subFromHighlightRow('subform_id', window.pkToDo); // <------- Replace subform_id with the object Id of the subform
		window.pkToDo = undefined;
	
	}
}	

function subFromHighlightRow(sfId, pk) {
    
    var sf = nuSubformObject(sfId);    
    for (var i = 0; i < sf.rows.length; i++) { 
            if (sf.rows[i][0] == pk) {
			    var c = $('#' + sfId + nuPad3(i) + nuSubformObject(sfId).fields[1]);
				c.css('color','#EC7063').focus();
				return;
			}
            
        }
 }

Re: Link to record in subform on a tab

Posted: Wed Nov 10, 2021 6:34 am
by kev1n
Hi, just wanted to follow up on this. Were you able to make it work?