Login / Register  search  syndication  about

          Ryan Farley's Blog

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

Creating a Business Rule to Return a List of Objects

One of the best things about working with the SalesLogix 7.2 Web application is how great the entity model is. You have this single place to put all your rules and logic, the UI is really just an afterthought. Something that I do quite often is create business rules to return data specific to an entity instance. For example, a rule to return the primary contact for an account. Let's take that a step further and return a list of objects from an business rule. For this scenario, we'll create a business rule that will return a list of child accounts for the current account instance.

To do this, go to the Account entity in the Application Architect and create a new business rule. Give the rule a name of GetChildAccounts. What we will be returning from this rule is a List<IAccount>. However, you'll get problems if you try to add that as the return type for the rule in some versions. That's fine, we can specify that we'll be returning an object and all will be OK (If the return type is object, you will have some problems with grids. It is better to manually type in the specific return type, like this: Add System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount> as the return type). Add a step for the rule and it will end up looking like the following:

Click the Edit Code Snippet and we'll enter the following code:

#region Usings
using System;
using Sage.Entity.Interfaces;
using Sage.Platform;
using Sage.Platform.Repository;
#endregion Usings

namespace Sage.BusinessRules.CodeSnippets
{
public static partial class AccountBusinessRules
{
public static void GetChildAccountsStep1( IAccount account, out object result)
{
IRepository<IAccount> repository = EntityFactory.GetRepository<IAccount>();
IQueryable qry = (IQueryable)repository;
IExpressionFactory ef = qry.GetExpressionFactory();

ICriteria criteria = qry.CreateCriteria();
criteria.Add(ef.Eq("ParentId", account.Id.ToString()));

result = criteria.List<IAccount>();
}
}
}

Let's talk about what that code is alll about for a sec. We first create a repository for IAccount. This is basically the "place" and "type" where we will be getting our data. We next create an IQueryable object which represents our query. We add an ICriteria, via the ExpressionFactory of our IQueryable object, which specifies that we want anything from our repository that meets the criteria that the entity's "ParentId" property equals the current account instance's Id value. From there we simply get a List of the results. I'll be posting a lot more about how to use and understand this syntax in the future, but I wanted to point out that it is all NHibernate under the covers. This means you can use HQL queries as well, which might make for more readable syntax for some. Either way, there is plenty of good info online already. See http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#querycriteria for starters.

Tomorrow we'll look at binding those results to a grid using the GetByMethod option for the datasoruce.

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
   Change the Appearance of a Saleslogix (Now Infor CRM) Read Only TextBox Web Control
In the Salelogix web client, a read only control has a css style applied to it to make the background app
Posted on Oct 24, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Saleslogix (now Infor CRM) Web Client- Changing Label Appearances on Quick Forms
 I wrote previously about setting a label's appearance on a quick form using server side code.&n
Posted on Oct 02, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Error Attempting to Save an Entity: "E_FAIL(0x80004005)" in the Infor CRM (Saleslogix) Web Client
We recently had a client that was running into an issue when attempting to create one particular entity i
Posted on Sep 30, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Video: Demystifying Infor CRM (Saleslogix) Updates
Watch it now! If you missed yesterdays demo, "Demystifying Infor CRM (Saleslogix) Updates" ,
Posted on Sep 26, 2014 by Brianna Ojard to The Inbox
 
   Official Infor CRM Acquisition FAQ
What to expect now that Saleslogix is Infor CRM. Like many of you, it will take some time (probably a
Posted on Sep 18, 2014 by Brianna Ojard to The Inbox
 
Comments

 

CRM Developer said:

I last posted about creating a business rule to return a list of objects. Today, I will take that a step further and bind the List to a DataGrid using the built-in GetByMethod for binding the list.

May 27, 2008 5:37 PM
 

DanCarvin said:

Hi Ryan,

I tried adding this business rule as you've presented this, but on build I'm getting "ERROR - C:\Documents and Settings\dan\Application Data\Sage\Platform\Output\Sage.SnippetLibrary.CSharp\src\Sage.SnippetLibrary.CSharp.@.94d415bc-d5e1-4fdf-b925-06e76a41cf7c.codesnippet.cs(40,22):Cannot implicitly convert type 'System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount>' to 'string'

I've deleted the sippet from Enity Model,/SLX App Entities/Account/Rules/Business Rule methods, but I'm still got the error, until I rebuilt with the Ctrl key.

July 1, 2008 4:17 PM
 

Ryan Farley said:

Hi Dan,

Sounds like you mistyped something. Are you sure you have this:

account.Id.ToString()

and not this:

account.ToString()

(notice the missing "Id")

-Ryan

July 1, 2008 4:38 PM
 

DanCarvin said:

I deleted it, so I think it's gone.   I know I copied & Pasted the main block of code in, then typed in the usings that don't automatically appear.

I'll let you know what happens when I try it again.

July 1, 2008 6:16 PM
 

Mike Boysen said:

Ryan, is this method still working for you?

March 19, 2009 12:18 PM
 

Ryan Farley said:

Hi Mike,

It is, although I usually don't set the return type to object, instead type in something like this for the return type (if you're binding to a grid especially)

System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount>

March 27, 2009 2:16 PM
 

CRM Developer said:

Binding a DataGrid at runtime is something that many SalesLogix developers are used to doing while working in the LAN client. This task is every bit as easy in the web platform as well. Let&#39;s take a look at how to put this together.

April 2, 2009 1:51 PM
 

SalesLogix Training » Blog Archive » Using iCriteria Like ADO (and some HQL too) said:

Pingback from  SalesLogix Training  &raquo; Blog Archive   &raquo; Using iCriteria Like ADO (and some HQL too)

September 1, 2009 4:54 PM
 

Business Objects Sdk Tutorial | Business Objects Tutorials said:

Pingback from  Business Objects Sdk Tutorial | Business Objects Tutorials

January 3, 2012 10:40 PM
 

Business Objects Sdk Tutorial | Business Objects Tutorials said:

Pingback from  Business Objects Sdk Tutorial | Business Objects Tutorials

January 3, 2012 10:40 PM
 

Silvana said:

What should i do if i need all the account contacts and at the same time join it with the tickets of the contact?

April 19, 2013 10:02 AM
 

Ryan Farley said:

Silvana,

The contacts already have a relationship to ticket. So, returning a list of contacts you could access that contact's tickets via contact.Tickets.

Ryan

April 20, 2013 5:43 PM
 

RJ Samp said:

Ryan, still getting the

"Cannot implicitly convert type 'System.Collections.Generic.IList<Sage.Entity.Interfaces.IAccount>' to 'string'"

I'm looking for a 'string' recordset of the Account Records......

Want to use the account[item].Account, account[item].Type, account[item].Status kinds of stuff.....

///should this be List or IList?

apl = criteria.List<IAccount>();

forEach (a in apl)

April 21, 2013 10:33 AM
 

Using iCriteria Like ADO (and some HQL too) | Saleslogix Training said:

Pingback from  Using iCriteria Like ADO (and some HQL too) |  Saleslogix Training

July 30, 2013 2:34 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