Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Avid Listener
Posts: 17
Registered: ‎03-09-2010

SLX Web - updating one field from another

SLX web v7.5.1

 

On the account details form I am trying to update an owner lookup field when the account manager field changes.

 

i.e. when the user changes the account manager on the account detail some sql is run to retrieve a seccodeid configured against that user and update an owner lookup control.

 

I have put some code in the load actions of the form and a refresh data action on the account manager field.  If I change the account manager nothing happens until I save the record, when I save the record the owner lookup field changes but it retrieves the seccodeid of the previous account manager.

 

This is the code I have in the load actions of the account detail form:

 

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();

string connection3 = service.GetConnectionString();System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(connection3);

con.Open();

System.Data.OleDb.OleDbCommand cmd = con.CreateCommand();

cmd.CommandText =
"SELECT MAX(PARENTSECCODEID) FROM SECCODEJOINS S1 INNER JOIN SECCODE S ON S1.PARENTSECCODEID = S.SECCODEID WHERE CHILDSECCODEID = (SELECT DEFAULTSECCODEID FROM USERSECURITY WHERE USERID = '" + account.AccountManager.Id + "') AND S.SECCODETYPE = 'D'";

 

if (cmd.ExecuteScalar() != DBNull.Value)

{

account.SalesDeptSeccodeId = (
string)cmd.ExecuteScalar();

 

}

 

 

cmd.Dispose();

con.Close();

Highlighted
Bronze Super Contributor
Posts: 129
Registered: ‎06-09-2009

Re: SLX Web - updating one field from another

I would think part of it has to do with the Refresh data on the Acct Manager field.

 

I have been able to get around this by making the Form a Smart Part and do the following:

 

  - Set the AutoPostBack to True.

  - Add a function to handle the Postback on the LookupResultValueChanged Event.

  - Put your code inside that handler and make the change on the Entity object (don't save)

 

 

  Also, on your code, you are executing the Query twice (once to check if it is null, and then once to assign it. I would suggest you do something like this:

  object result = cmd.ExecuteScalar();

  if (result != null)

  {

   account.SalesDeptSeccodeId = result.ToString();   

  }

 

 

 

Raul A. Chavez
http://raul.chavez.com
http://www.crmbi.com