Show detail form

On my form (call_dtl) i have a field (call_customerid) linked to a valuelist with customers. Next to it I have a button to show the detailform of the selected customer.

I want to create a generic OnAction eventhandler so i can use the same event for similar fields. I can show the correct program, but i’ve got some problems setting the foundset of that program to the correct record.
for the above example it is called using the folowing parameters:

  • _program = ‘customers’
  • _fld = ‘call_customerid’
    NB: The id field of the customertable = ‘customer_id’
/**
 * Perform the element default action.
 *
 * @param {JSEvent} _event the event that triggered the action
 * @param _program the program needed to show
 * @param {JSField} _fld the field that contains the id of the record that has to be shown
 *
 * @properties={typeid:24,uuid:"1E80FED4-43A5-48D7-BA05-987D8625ED7C"}
 */
function ShowSelected(_event, _program, _fld)
{
	if(globals.nav.mode != 'browse') return; // no navigation in find and edit
	if(!globals.nav.program[_program] || globals.nav.program[_program] == undefined) return
	if(_fld == undefined) return; // no value to show

	globals.nav.history = new Object()
	
	var _template = globals.nav.template_types[globals.nav.program[_program].view]
		
	var _form = globals.nav.program[_program].form[forms[_template].has1()][2]         

	// show the program
	var _return = globals.svy_nav_showForm(_form, _program); 
	// sort the tables
	if(_return == -1) 
	{
		return
	}
	if(_return[0])// only if there are tabs
	{
		forms.svy_nav_base.dc_sort( _return[0],  _return[1]);
	}
	// find the record
	if(forms[globals.nav.form_view_01].controller.find())
	{
		forms[globals.nav.form_view_01]['customer_id'] = 'D8A05953-6ED8-4384-8C9C-915E2351EE0A' // <== how do i make this use the _fld parameter??
		forms[globals.nav.form_view_01].controller.newRecord()
		forms[globals.nav.form_view_01].controller.search()
	}
}

For now this function is in call_dtl.js, but eventually has to be moved to globals. When i debug my code i can get the element details in interactive console:

=>elements[_fld]
TYPE_AHEAD[name:call_customerid,x:310,y:40,width:220,height:20,value:D8A05953-6ED8-4384-8C9C-915E2351EE0A] {bgcolor:“#ffffff”,caretPosition:0,editable:false,enabled:true,fgcolor:“#000000”,format:null,readOnly:true,toolTipText:null,transparent:false,visible:true}

I can see it has a value, but elements[_fld].value returns Undefined.

Jos

jdbruijn:
forms[globals.nav.form_view_01][‘customer_id’] = ‘D8A05953-6ED8-4384-8C9C-915E2351EE0A’ // <== how do i make this use the _fld parameter??

assuming ‘call_customerid’ is a column in the table where the program ‘customers’ is based on.

forms[event.getFormName()][_fld] should return the correct value.

Hope this helps

Thanx Marc,

That does return the correct value.

Do you also have a suggestion on how to retreive the correct ID column for a given form?

forms[globals.nav.form_view_01][‘customer_id’] = forms[_event.getFormName()][_fld]

jdbruijn:
Do you also have a suggestion on how to retreive the correct ID column for a given form?

Assuming you work with single column pk’s, this would do the job:

var _dataSource = forms[globals.nav.form_view_01].controller.getDataSource();
var _jsTable = databaseManager.getTable(_dataSource);
var _pkFld;

if(_jsTable) _pkFld = _jsTable.getRowIdentifierColumnNames()[0];
	
if(_pkFld && forms[globals.nav.form_view_01].controller.find())
{
forms[globals.nav.form_view_01][_pkFld] = forms[_event.getFormName()][_fld];
forms[globals.nav.form_view_01].controller.newRecord();
forms[globals.nav.form_view_01].controller.search();
}

Excelent,

Thank you Marc

You might want to create a small global method to retrieve the pkFld, as you might need this a couple of times more…