Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Contact Me
  • Welcome

Validation of SalesLogix Lookup Controls

Nicolas Galler | March 8, 2010

OK so I am really, really loving JQuery lately. This is a neat use of how to add a custom validator for a lookup control in SalesLogix. The lookups have this “Required” property which you can turn on to make them required, but this has 2 major flaws:

  • Can’t specify the validation group, in case you want the lookup to only be validated in certain cases
  • More importantly, can’t specify an error message, so you are left with the default tiny-ish red asterisk. I don’t know about you but I like my error message to be big, bold, and explicit.

So we have this RequiredFieldValidator, part of the standard ASP.NET controls. This is so handy for validating textboxes but if you try to have it validate a lookup you will get this beautiful error message:

Control 'luePurchContact' referenced by the ControlToValidate property of '' cannot be validated.

There is a customvalidator that lets you specify your own validation function, and you can do that. This would look something like:

 <asp:CustomValidator ID="CustomValidator2" runat="server" ValidationGroup="SubmitCredit" Text="*" OnServerValidate="luePurchContact_Validate"
                ErrorMessage="Please select Purchasing Contact"/>

and then in the code behind:

    void luePurchContact_Validate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = (luePurchContact.LookupResultValue != null);
    }

The big problem here is that this requires a postback. Postbacks are slow. You want to avoid them as much as possible. They waste bandwidth, server CPU, client CPU, they look ugly, they cause the control focus to be lost, and they mess up Javascript customizations. They suck. Furthermore, if some controls require a postback to validate, and some don’t, the users will only get a partial validation at a time, which is annoying.

Anyway, Microsoft thought the same thing of postbacks, and they provided an extension to these customvalidators that let you do the validation in Javascript. So the only difficulty is, how do we retrieve the lookup’s value in Javascript? It’s very easy if you know the client id, but ASP.NET has this nasty tendency to mangle those. Not a big deal though, as JQuery is still able to find controls based on the last characters of the id (assuming there is no other control with that same id in the page). This lets me write the following for validation:

<asp:CustomValidator runat="server" ValidationGroup="SubmitCredit" Text="*"
 ErrorMessage="Please select Purchasing Contact"
 ClientValidationFunction="(function(s, e) { args.IsValid = !!$('input[id$=luePurchContact_LookupResult]').val(); })" />

If you are suspicious about another lookup with the same id on another part of the page, use the following instead:

<div id="frmAccCredit">
<!-- 
  "frmAccCredit" would be a unique identifier for the form.
  You can use anything that is going to be unique, and put it at top level of the form.
  This is also handy for designing css rules that should not affect other
  parts of the page.
-->

...
more stuff
...

<asp:CustomValidator runat="server" ValidationGroup="SubmitCredit" Text="*"
 ErrorMessage="Please select Purchasing Contact"
 ClientValidationFunction="(function(s, e) { args.IsValid = !!$('#frmAccCredit input[id$=luePurchContact_LookupResult]').val(); })" />
Comments
No Comments »
Categories
Uncategorized
Comments rss Comments rss
Trackback Trackback

Compress database backups with Powershell

Nicolas Galler | January 18, 2010

Disk space may be cheap but it is still not free! And, while SQL Server 2008 supports online compression of backups, it is only available in the Enterprise edition. So I wrote a simple powershell script (more like a snippet) to compress any backup (.bak and .trn files) older than 2 days.


cd E:\MSSQL\BACKUP\SalesLogix
dir *.trn,*.bak | where { $_.CreationTime.CompareTo([DateTime]::Now.AddDays(-2)) -lt 0 } |% `
{ & 'C:\Program Files\7-Zip\7z.exe' a "$_.zip" $_; rm $_ }

Could replace “.zip” with “.7z” to do a 7-zip compression – it will take a bit less disk space but more cpu. Could also be tweaked a bit to support recursion.

I saved that to E:\MSSQL\Backup\ZipBackups.ps1 and created a schedule task to invoke “powershell E:\MSSQL\Backup\ZipBackups.ps1″. This requires the execution policy to be set on powershell, to allow unsigned local scripts:


set-executionpolicy RemoteSigned

I am still working on getting more familiar with powershell as it can be a nifty tool (and is becoming more and more standard on Windows servers as it is bundled with other packages)

Comments
No Comments »
Categories
Tricks
Comments rss Comments rss
Trackback Trackback

More random errors.

Nicolas Galler | January 13, 2010

A quick offering to the great Google god, in case you are running into the same issue:

  • “NullReferenceException” in the “ExtractValuesFromCell” method – this is caused by the “pseudo” cell added by the SlxGridView. To work around, turn off the “ExpandableRows” flag.
  • Blank page with a NullReferenceException in the LookupControl ClientConfiguration.From method: check the provider listed in connection.config. It needs to be spelled “SLXOLEDB”. If it is spelled out “SalesLogix OLEDB Connection Provider”, it will fail (not sure why but on 7.5.2 sometimes the connection is output in that format – I think, because I created the connection in AA, instead of logging into the Admin first)
  • Web client crashes when grid.Sort is called – do not call that method from the Sorting handler because it will cause infinite recursion (the Sorting handler can often be empty)
  • AA gives ArgumentNullException when Update Properties is clicked: this is an installation problem. Run a repair. In fact, if you get random errors from AA, and they are not specific to one project, running a repair should probably be the first corrective action.
Comments
No Comments »
Categories
Saleslogix
Comments rss Comments rss
Trackback Trackback

Using Direct SQL in Web Grids

Nicolas Galler | January 8, 2010

Another (thankfully smaller) post on the SalesLogix journal, detailing how to use straight SQL in a web grid. I use that a lot when I have a complex, read-only query (so much faster than cranking out the corresponding C# code to do it through the entity model), and I know a lot of SalesLogix dev are very familiar with SQL, so figured it would be useful.

The article is at Back to Basics – Using Direct SQL in Web Grids

Comments
No Comments »
Categories
Saleslogix
Comments rss Comments rss
Trackback Trackback

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (24)

Post History

  • 2010
    • January (3)
    • March (1)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox