Finding the Current Parent Record ID in SalesLogix Web

Sometimes it’s the easiest things that can be a big barrier to entry for getting started with something. I was reminded of this recently with some forum posts on slxdeveloper.com. Something as simple as getting the ID value of the current record can get in the way of getting the real work done if you’re just getting started. Since I couldn’t find an existing blog post on this topic on our website I figured it was time. Let’s take a look at a few different ways to do this.

Like many things in SalesLogix Web, there are a few different ways to do this, depending on where you’re using the code.

In a Code Snippet Action

A Code Snippet Action you can write code in C# or VB.NET since a Code Snippet Action is compiled into a separate DLL that is referenced by the web client. In a Code Snippet Action you have a built-in reference to the form which you can use to get to other things, such as the EntityContextService. Here’s the code:

// Get a reference to the EntityContextServce
// and call GetEntity() - note, in this example are current entity is an account
IAccount myparent = form.WorkItem.Services.Get<Sage.Platform.Application.IEntityContextService>().GetEntity() as IAccount;

In a C# Snippet Action

A C# Snippet Action is different than a Code Snippet Action. As the name implies, it can only be C#. This is because it is placed right into the ASCX user control when you build the web platform (and SalesLogix is a C# application). The form, or user control, is called a SmartPart. It has a built in method called GetParentEntity that will do the job nicely. Here’s the code:

Sage.Entity.Interfaces.IAccount myparent = this.GetParentEntity() as Sage.Entity.Interfaces.IAccount;

In Client-Side Javascript

If you happen to be creating client-side javascript, you can get the current record ID there as well using the ClientEntityContext service.

var contextSvc = Sage.Services.getService('ClientEntityContext');
var context = contextSvc.getContext();
var entityId = context.EntityId; 

As an ASP.NET Query String Parameter

Lastly, since SalesLogix is an ASP.NET application, and when you access a record there is always an “entityid” parameter in the URL, you can resort to just ASP.NET methods to get the value from the query string.

string id = Request.QueryString["entityId"];

One thing to note: If your entity has a relationship to the parent, you can also access the parent via the relationship’s object property. However, if the code is in a LoadAction for an Insert form, the parent will not yet have been set.

ABOUT THE AUTHOR

Ryan Farley

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

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!