Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Monday, February 24, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: Using the EntityFactory.Create<> for a custom User table
Ken Poggensee
Posts: 71
 
Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Aug 08 5:37 PM
I have a custom user table that I am storing certain page hits to. I first check and see if my record (for the currently logged in user) exists, if it does then I go update my counter. This part works fine.

What I am having a problem with is with new records. When I go try to create a new entity the system is auto-creating the UserID for me with a generic id ‘Q6UJ9A016211’. Sure…that kind of make sense and is awfully nice of then because now I don’t have to worry about creating an ID. Of course my problem is that I need that UserID field to be the UserID of the currently logged in user. I try to set the UserID field in the code before I save, but it just ignores it. The Id field is read-only so I can’t set it there.

So how do I get my entity saved with the Id I specify?

Below is my code:
--------------------------------------------------------------
Sage.SalesLogix.Security.SLXUserService curUser = Sage.Platform.Application.ApplicationContext.Current.Services.Get() as Sage.SalesLogix.Security.SLXUserService;

Sage.Entity.Interfaces.IWebUsage webUsage = Sage.Platform.EntityFactory.GetById(curUser.UserId.ToString());
if (webUsage == null)
{
Sage.Entity.Interfaces.IWebUsage webUseInsert = Sage.Platform.EntityFactory.Create();
//This Userid property is getting ignored during the save.
webUseInsert.Userid = curUser.UserId.ToString();
webUseInsert.AccountHits = 1;
webUseInsert.Save();
}
else
{
//This all works fine. Just update a counter field.
int accHits = Convert.ToInt32(webUsage.AccountHits);
accHits++;
webUsage.AccountHits = accHits;
webUsage.Save();
}


--------------------------------------------------------------

Thanks in advance for any pointers you can provide.

--Ken--
[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Aug 08 3:27 AM
Im guessing UserId is the primary key for the table? I must admit I have never had to set the primary key of a table before. You could try setting

webUseInsert.Id - to what you need (instead or as well as userid).

Although Im thinking SLX will still override it with its ID....worth a go though.

[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Aug 08 7:37 AM
Ken, Looks like the table is not really an extension table to the UserInfo entity. Cannot be anyways I believe the User (security entities) are not customizable. In 7.5 there is facilities for overwritting the Id of the entity (an interface was not exposed in 7.2x). Your best bet really is to just use the IDataService and do the actual write yourself. you can read the entity/test through the model initially but probably want to insert the record with good old SQL
[Reply][Quote]
Ken Poggensee
Posts: 71
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Aug 08 10:50 AM
Your are correct that the user tables are not available in the 7.2. What I did was create the 1:1 table off user info in a prior version and bundled it to my upgraded DB. The table and JoinData records for the table came over just fine. Everything else seems to be ok, except this one situation. What scares me is I have several clients where I have added extension tables of User tables to store data particular to users. Looks like I am going to have to manage those manually now.

You mentioned the IDataService and raw SQL... I am going to show my noobness now and admit that I have not used it yet. However, I would MUCH rather being dealing with good 'ole SQL than entities and what not (old dog, new tricks syndrome). So with that being said, do you have a simple script you could share that does this?

...Pretty Plz

--Ken--
[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Sep 08 11:27 AM
Hi Ken,

To write some simple SQL this should do the trick...:

//Get your Conn String..

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string constr = service.GetConnectionString();
//Declare your command, and connection pieces..
System.Data.OleDb.OleDbCommand comm;
System.Data.OleDb.OleDbConnection conn;

conn = new System.Data.OleDb.OleDbConnection(constr);
conn.Open();

string sql = "UPDATE USERTABLE SET BLAH = BLAH WHERE USERID = '" + currUserIdVar.... + "'"

comm = new System.Data.OleDb.OleDbCommand(sql, conn);
comm.ExecuteNonQuery();


//Cleanup..
comm.Dispose();
conn.Dispose();


Thats off the top of my head but looks correct - let me know if you have any issues.

Cheers,
Nick
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Sep 08 7:14 AM
Ken, Nick the code posted would work. I would however put the creation of the connection and command within a set of using statmements ensuring that the objects do indeed get disposed even in the case of an exception.

Mark
[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Using the EntityFactory.Create<> for a custom User tableYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Sep 08 7:44 AM
Yes good point Mark...so something like:

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string constr = service.GetConnectionString();

string sql = "UPDATE USERTABLE SET BLAH = BLAH WHERE USERID = '" + currUserIdVar.... + "'"

using (System.Data.OleDb.OleDbConnection conn = new OleDbConnection(constr))
{
conn.Open();
using (System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand(sql, conn))
{
comm.ExecuteNonQuery();
}
}

-ish anyway!

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 2/24/2025 2:43:54 AM