Dumb Question... newRecord() + Defaults Column Data?

Hi Folks

Prolly a really dumb question but how can I use the newRecord() function of the controller to add the record, and also add specific column data at the same time.

e.g. I need to add a new component record but the record needs to have the current users SaaS id placed in the SaasID column.

Is this possible with the newRecord function or do I haveto have a function called on the onNewRecord event? If its the latter is it a case of creating SQL to do the data entry or am I over complicating things again (Servoy constantly surprises me with what it saves me doing manualy!).

Appreciate feedback

you could think of adding a table event to your tables. (you find this on the ‘events’ tab of the table definitions)

the onRecordInsert method could be something like this:

function onRecordInsert()
{
	var $rec		= arguments[0];
	var $jsTable	= databaseManager.getTable($rec);
	var $columns	= $jsTable.getColumnNames();
        
        if($columns.indexOf('SaasId') > -1) $rec.SaasId = globals.currentSaasId;       

}

This method can be easily extended to other columns like creationDate, creationUser, etc.

Marc - I’m now convinced - I should get a dedicated ‘Bat Phone’ connection directly to you :lol:

Thanks again Bud!

I would setup a global relationship to the current SaaS account record. ie, at login, set a global to the account_id, and make a relationship:

current_account
globals.current_account_id = accounts.account_id

Then use an auto-enter lookup value on the column in the data-provider.

greg.

agiletortoise:
I would setup a global relationship to the current SaaS account record. ie, at login, set a global to the account_id, and make a relationship:

current_account
globals.current_account_id = accounts.account_id

Then use an auto-enter lookup value on the column in the data-provider.

greg.

Thanks Greg - yes I see the logic in that for the instance of the SaasID. I’ll put that in place for the SaaSID.

Though that one is just an instance as I’ll need to add various other data automatically dependant upon the table in question. So some will have user info (name etc) and others dates, and so on.

The table insert event is good for that, if you only want it filled in at the time it goes to the database.

Typically for this type of thing, you want those values filled in before the user views/edits the record, not later on.

For this, I use global form events and callbacks. See this blog post for the general idea: http://blittle.us/9Yx4

greg.

agiletortoise:
The table insert event is good for that, if you only want it filled in at the time it goes to the database.

Typically for this type of thing, you want those values filled in before the user views/edits the record, not later on.

For this, I use global form events and callbacks. See this blog post for the general idea: http://blittle.us/9Yx4

greg.

I guess my target is to have a new record created and the relevant columns populated as its presented to the user. Hence th thought of using newRecord()!

I suspect the easiest way is simply to hard code the thing and do newRecord(), make it the selected record, then inset the values into the fields on the form (be they visible or not as the case may be).

Does tht make sense or am I missing the point?

Just to throw some more code into the pot that might be useful.

We recently had requirement for online/offline system using MSQL2000(!) and needed to create unique Record ID’s that were also consecutive.

To create a new Company record together with linked Address record. Note that every Table has a developer form named wx_company, wx_address etc, plus a global.variable called curr_Company_ID, curr_Address_ID etc

		//	create new COMPANY record
		var vForm = 'wx_company';
		globals.SetNewRecord_ID(vForm);
		
		//	create a linked ADDRESS record
		var vForm = 'wx_address';
		globals.SetNewRecord_ID(vForm);
		
		//	load Comp_ID & helper text into the new record
		curr_addressid_to_address.zrid_company = globals.curr_Company_ID;
		curr_addressid_to_address.address 	  = 'Enter address here';
	
		//	load new COMPANY record & view in FID
		globals.GUI_Title_FID = 'A d d   n e w   C o m p a n y';
		forms.company__p_addedit.controller.loadRecords(curr_companyid_to_company )
		var vTab = 1;
		globals.show_FID(vTab)

global method

function SetNewRecord_ID()
{
	var vForm	= arguments[0];

	var vField 	= 'zzid_' + vForm.substr(3);			//	setup the ID field
	var vGlobal	= 'curr_' + utils.stringInitCap(vForm.substr(3)) + '_ID';	//	setup the Global_currID field to store new record ID
	
	var vInits	= globals.curr_Staff_Initials;				
	var vDate	= new Date();
	var vMills	= vDate.getTime();
	var vRecID	= vInits + '_' + vMills;
	
	forms[vForm].controller.newRecord(true);
		forms[vForm][vField] = vRecID;
		
		globals[vGlobal]	 = forms[vForm][vField];		//	store the new curr_xxx_ID value
		
	databaseManager.saveData();
}

Can then extend this to add linked records:

	//	create new LINK PROF record
	var vForm = 'wx_link_professional';
	globals.SetNewRecord_ID(vForm);
	var vRecord = curr_link_professionalid_to_link_professional.getRecord(1);
		vRecord.zrid_company	= globals.curr_Company_ID;
		vRecord.x_createby		= globals.curr_Staff_Initials;

HTH

Thanks Graham - comprehensive as always :wink:

Cheers