Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Link to record in subform on a tab

Questions related to using nuBuilder Forte.
Post Reply
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Link to record in subform on a tab

Unread post 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?
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Link to record in subform on a tab

Unread post 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?
treed
Posts: 205
Joined: Mon May 18, 2020 12:02 am
Been thanked: 2 times
Contact:

Re: Link to record in subform on a tab

Unread post by treed »

That would be perfect!
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Link to record in subform on a tab

Unread post 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;
			}
            
        }
 }
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Link to record in subform on a tab

Unread post by kev1n »

Hi, just wanted to follow up on this. Were you able to make it work?
Post Reply