Thursday, November 20, 2008 ..:: Forums ::.. Register  Login
 Forums Minimize
SearchForum Home
     
  Mainstream Forums  Developers  What's the righ...
 What's the right way to add custom columns to exist module like "Accounts"?
 
dragoon
19 posts
Joined
6/5/2008

What's the right way to add custom columns to exist module like "Accounts"?
Posted: 15 Aug 08 4:38 AM Modified By dragoon  on 8/15/2008 5:14:03 AM)

Hi,
I modified some modules, included "Accounts", "Users", "Contacts", by the way like this:
1. modify BaseTables\ACCOUNTS_CSTM.1.sql to add custom columns.
2. rebuild Views\vwACCOUNTS.1.sql and any views that reference to ACCOUNTS_CSTM and vwACCOUNTS.
3. modify Procedures\spACCOUNTS_Update.1.sql to add the custom columns to the declaration and update the code to table "ACCOUNTS_CSTM" like this:
  if not exists(select * from ACCOUNTS_CSTM where ID_C = @ID) begin -- then
    insert into ACCOUNTS_CSTM
      ( ID_C
      , CUSTOM_COLUMN_1
      , CUSTOM_COLUMN_2
      ...
      )
    values
      ( @ID
      , @CUSTOM_COLUMN_1
      , @CUSTOM_COLUMN_2
      ...
      );
  end else begin
    update ACCOUNTS_CSTM
       set CUSTOM_COLUMN_1 = @CUSTOM_COLUMN_1
         , CUSTOM_COLUMN_2 = @CUSTOM_COLUMN_2
         ...
     where ID_C = @ID;
  end -- if;

4. modify three functions in _code\SqlProcs.cs have the names : spACCOUNTS_Update(), spACCOUNTS_Update(), cmdACCOUNTS_Update. To add new variables to their declarations and add some code like this:

IDbDataParameter parCUSTOM_COLUMN_1 = Sql.CreateParameter(cmd, "@parCUSTOM_COLUMN_1" , "string",  255);

5. modify Accounts\EditView.ascx.cs whose calls SqlProcs.spACCOUNTS_Update().
6. maybe some small modification that I can't remember now

The method above works quite well now.

My question is that: is it necessary to do steps 3 to 6?
My question raised when I understand SplendidDynamic.UpdateCustomFields() maybe try to help me doing all nasty things already. When I go to the declaration of SplendidDynamic.UpdateCustomFields(), I think it may meet some problem when I utility drop down list to set the value of my custom columns. Now I use new DynamicControl(this, rowCurrent, "aColumnName").SelectedValue to get the value from drop down list, I have no idea of it would work or not to a drop down list.

Since there is no clear document to explain all this, althought my method works quite well now, I want to hear explicit answer from the author. By the way, I don't use any admin function to add columns, since I think it would be more effective to modify sql code for me, (one reason is easier to deploy to customer environment and sync the state of both of development and production).

With best regard,
Dragoon

support
2098 posts
1st
Joined
1/3/2006

Re: What's the right way to add custom columns to exist module like "Accounts"?
Posted: 15 Aug 08 11:56 AM

You have two options for adding custom fields.  One is to do it online, the other is to use the spFIELDS_META_DATA_Insert procedure (which is used online).  The reason is that the meta data record is necessary to allow the custom to field to be automatically updated when an account is saved.

 exec dbo.spFIELDS_META_DATA_Insert null, null, 'ACCOUNT_HANDLER', 'Account Handler', 'ACCOUNT_HANDLER', 'Accounts', 'varchar', 40, 0, 0, null, null, 0;

You can modify the spACCOUNTS_Update procedure as you have done, but then it becomes more difficult to apply a SplendidCRM update.

  Mainstream Forums  Developers  What's the righ...

Forum Home  Search       

Copyright (c) 2006-2008 SplendidCRM Software, Inc. All Rights Reserved.   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2008 by Perpetual Motion Interactive Systems Inc.
SplendidCRM and SplendidCRM Software are trademarks of SplendidCRM Software, Inc. SugarCRM is a trademark of SugarCRM Inc. in the United States, the European Union and other countries. All other trademarks used in this web site are the property of their respective owners.