back to top

Using Selected Rows in an Editable Grid in a Server-Side C# Action in Infor CRM Web

In my previous article I discussed using the ClientContextService to pass values from client-side code to a server-side C# action. We will use that idea here to allow a server-side C# action to know which rows are selected in an Editable Grid.

The Editable Grid control in Infor CRM isn’t an ASP.NET control. Instead, it adds Javascript to create a completely client-side Dojo grid that uses SData. It’s a 100% client-side control. This means, if you want to use it from a server-side action you’re out of luck. However, using the ClientContextService you can pass information from client-side code to your server-side action, allowing the C# code to work with the Editable Grid.

In this scenario, we have an Editable Grid, with standard buttons next to it to perform actions on the rows selected by the user. The buttons have C# actions to perform updates and other actions on the selected rows in the grid. The user can select one, or many, rows and click one of the buttons to trigger a postback and perform some actions. The tricky part is, we need to let our server-side C# action know which grid rows the user has selected.

The first step is, we need to wire up some Javascript to the OnClientClick of the buttons. The OnClientClick Javascript code executes prior to the postback. We can return true or false to allow, or prevent, the postback from occurring. In the code below we get the selected rows from the Editable Grid and then set it in the ClientContextService. If no rows are selected, we alert the user and return false and everything stops (the C# action will not execute).

The following code is in a LoadAction to wire up the Javascript to the OnClientClick of our button.

// first we need to determine the client-side name of our Editable Grid
var gridId = string.Empty;
foreach (Control ctrl in Controls)
{
    var resCtrl = ctrl as ScriptResourceProvider;
    if (resCtrl != null)
    {
        gridId = resCtrl.ID.Replace("_Strings","");
        break;
    }
}

// this is the client-side script. In this code, we get a reference to the grid
// and then get the selected rows. We set the selected rows in the client context
// service. If no rows are selected we alert the user.
var script = @"var grid = dijit.byId('{0}'), 
				   selectedIds = grid.selection.getSelected().map( function(row) { return row.$key; }).join(); 

			   if (selectedIds != '') { 
				   var context = Sage.Services.getService('ClientContextService'); 
				   context.remove('SelectedGridRows'); 
				   context.add('SelectedGridRows', selectedIds); 
				   return true; 
			   } 
			   else { 
				   alert('There are no selected rows.'); 
				   return false; 
			   } ";

// now wire up the OnClientClick of our button 
button1.OnClientClick = string.Format(script, gridId); 

Now, when our button is selected, the Javascript we wired up to the button will execute and the ID’s of the selected rows will be added to the client context service. Now, in the code for the button, we can use the client context service to get the IDs of the selected rows. The code for the button will look like this:

var contextService = PageWorkItem.Services.Get<Sage.Platform.WebPortal.Services.ClientContextService>();
if (contextService.CurrentContext.ContainsKey("SelectedGridRows"))
{
	var selectedIds = contextService.CurrentContext["SelectedGridRows"].Split(',');
	// now the selectedIds variable is an array of the ID values of the selected rows
	// we can loop through them and do whatever is needed
	
	// for example:
	foreach (var id in selectedIds)
	{
		// this is just an example...
		var contact = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IContact>(id);
		contact.Status = "Something";
		contact.Save();
	}
}

Not too bad. It gets the context of the selected Editable Grid rows back to C# so you can do anything you’d like at that point.

Contact Customer FX for your CRM project
We let our expertise speak for itself - let us know how our all-star team can help on your CRM project
About the Author
Ryan Farley
Ryan Farleyhttps://customerfx.com/article/author/ryanfarley/
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. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

7 COMMENTS

  1. I’m having difficulty with this:
    Does it have to be an editable grid?
    What if the grid is in a Dialog Workspace?
    Where, exactly, does this code go? (I have tried in the main.js file for the top bit and the OnClick C# action for the bottom bit)
    Is there another method for passing selected rows?
    Is this enough questions?

    Many thanks

    • This method only works with editable grids, it doesn’t have to be made as “editable”, but it does work only with editable grids. There are other methods for doing similar with standard datagrids. It works if the editable grid is in the dialog workspace. This is all C# code. The C# does inject javascript onto the page, but it’s C# code doing this. The first bit of code needs to go in a LoadAction. The second bit goes wherever you need to retrieve the selected rows, such as the action for a button click.

    • I’m getting there, but now I am getting an ‘Input string is not in correct format’ error. It has something to do with the script var. I have injected a simple alert(); and the blank message window pops open but something is going awry with the script variable. Is this a known issue? I shall persevere and report back what I figure out.

    • Update: Input string error has been resolved by building the string in two stages.
      var script = string.Format(“var grid = dijit.byId(‘{0}’)”, gridId);
      script += @””;

      Now, however, the .selection property of the grid is reading as ‘undefined’ but I can’t figure out why. Any guidance or alternative methods of getting the data in a selected row more than welcome.

      Many thanks,
      Matt

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Infor CRM SLX 10.0: Delegate Ownership Changes for “Everyone” Records

Learn how the new EveryoneOwnerAssignment secured action in Infor CRM SLX 10.0 allows designated users to change ownership of Everyone-owned records without requiring Administrator access.

Related Articles

Infor CRM Sync for Exchange: Action Required by August 31, 2026

Using Infor CRM Sync for Exchange with Microsoft 365? Your Exchange administrator must update tenant settings by August 31, 2026 to prevent sync disruption.

[Webinar] What’s Coming Next for Infor CRM SLX and Why v10 Matters

See what’s coming next for Infor CRM SLX, including new marketing workflows, automation improvements, and reasons to consider upgrading to v10.

Disable Caching in Infor CRM SLX Web Client

In the rare case caching is causing issues in the Infor CRM SLX web client, it is possible to disable specific types of caching by making edits using Application Architect, and then deploying.

Exploring AI Options for Infor CRM v10

I've started taking a closer look at the AI capabilities built into Infor CRM v10. Over the next several posts, I'll share what I learn. From the built-in features and supported AI providers to implementation considerations, costs, and practical use cases.

Related Videos