Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

Elegant SalesLogix Table ID Class in C#

I've been using the following C# class for creating SalesLogix table ID values lately and I just love the elegant syntax it provides. It's really been growing on me.

Here is the class:

using System;
using System.Data.OleDb;

namespace SalesLogix.Utility
{
    public class TableID
    {
        private string _table = string.Empty;

        public TableID(string TableName)
        {
            switch (TableName.ToUpper())
            {
                case "ATTACHMENT": _table = "FILEATTACH"; break;
                case "USERNOTIFICATION": _table = "USERNOTIFY"; break;
                case "AGENTS": _table = "HOSTTASK"; break;
                case "RESOURCELIST": _table = "RESOURCE"; break;
                case "USEROPTION": _table = "USERVIEW"; break;
                case "JOINDATA": _table = "JOIN"; break;
                case "PROCEDURES": _table = "PROCEDURE"; break;
                case "SEC_FUNCTIONOWNER": _table = "FUNCTIONHANDLER"; break;
                default: _table = TableName; break;
            }
        }

        public override string ToString()
        {
            return this.Value;
        }

        public string Value
        {
            get
            {
                using (OleDbConnection conn = new OleDbConnection(Globals.ConnectionString))
                {
                    conn.Open();
                    using (OleDbCommand cmd = new OleDbCommand(string.Format("slx_dbids('{0}', 1)", _table), conn))
                    {
                        return cmd.ExecuteScalar().ToString();
                    }
                }
            }
        }
    }
}

Nothing out of the ordinary there, but the really nice part comes from it's usage:

string ticketid = new TableID("ticket").Value;

I like it :-)

What's This?
  
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series



Related Content
   Using a Test Plan
So you have approved the Statement of Work (SOW) for some modifications and are awaiting the delivery of
Posted on Mar 13, 2014 by George Jensen to George Jensen's Blog
 
   Creating a Saleslogix Ticket Pretty Prefix and Suffix in External Applications
Some entities in SalesLogix, such as Tickets, use a "pretty key" as an easier to use value to r
Posted on Feb 28, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Evaluating strings in C# Code snippets
When checking for two (or more) different values for a property in a code snippet, you can't simply l
Posted on Dec 13, 2013 by Jason Buss to Jason Buss' Blog
 
   Introducing the SalesLogix Mobile Developer Toolkit
I am very pleased to announce a new & free open source tool from Customer FX named the SalesLogix Mob
Posted on Nov 13, 2012 by Ryan Farley to Ryan Farley's Blog
 
   Exporting Table data via the SalesLogix web client
Recently, I had a request to create export functionality for a datagrid in the SalesLogix web client. I
Posted on Feb 22, 2012 by Jason Buss to Jason Buss' Blog
 
Comments

 

Mark Dykun said:

Ryan,

Like the method. I would add a second method to the class Values that can return an array of id's as well.

Mark

May 7, 2008 3:01 PM
 

Ryan Farley said:

I've not used this in an app yet that had a need for multiple ID values to be created at once, but that would be a great addition.

Signature would look like:

public List<string> Values(int Count)

Which would make for some nice syntax:

List<string> idlist = new TableID("ticket").Values(10);

Very nice.

-Ryan

May 7, 2008 3:13 PM
 

Jim Forte said:

Question. I am trying to build a contactID outside of windows in perl, using freeTDS. Any thoughts on how I can build it without the functions built into sales logix?

May 8, 2009 2:35 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register