Showing a Message to the User from a Code Snippet Action in SalesLogix Web

Showing a message to a user in SalesLogix Web is an easy task. It should be, right? Of course – and it is, however, you might need to know where to look to do it. This post will take a look at how to do this from both a Code Snippet Action and a C# Snippet Action.

Showing a message in the web client, like using MsgBox from a LAN client script, requires use of the DialogService. The DialogService has a ShowMessage method you can use to display a message to the user.


From a Code Snippet Action

To use the DialogService from a Code Snippet Action, you need to use the form’s WorkItem reference that is passed in to the code action. This will allow you to get access to the DialogService.

// Get a reference to the DialogService
var dialogService = form.WorkItem.Services.Get<Sage.Platform.WebPortal.Services.IWebDialogService>();
// Now show a message to the user
dialogService.ShowMessage("You must first do something.");

Easy enough, now let’s take a look at how to do this from a C# Snippet Action.

From a C# Snippet Action

From a C# Snippet Action things a a little different. As I mentioned before, code in a C# Snippet Action gets placed directly on the SmartPart (the ASCX UserControl). The code is inline on the deployed ASCX file itself. The SmartPart inherits from EntityBoundSmartPartProvider which eventually inherits from Sage.Platform.WebPortal.SmartParts.SmartPart which has a built-in DialogService reference. What this means is that you no longer have to get a reference to the DialogService yourself, you just use the one you already have.

// Show a message to the user
this.DialogService.ShowMessage("You must first do something.");

Either way, whether you’re in a C# Snippet, or the Code Action things are all nice and simple, as it should be.

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. 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.

3 Comments

  1. Hi Steve,

    The whole idea of business rules is that the rule is a separation of logic from the UI. The rule operates at the entity level, not on the UI. A rule is better used to return some value like a boolean, leaving the prompting of some message to the UI layer.

    Eventually (in the very near future), you’ll be able to invoke business rules from SData as well, which obviously could cause problems if you did UI interaction type of things in the rule.

    So, back to your question, no, you can’t (and really shouldn’t anyway) do this sort of thing inside of a business rule. Instead, have your rule return some value and then use a DialogAction or in code display the message based on the returned value.

    -Ryan

    Reply
  2. Hi Ryan,

    I am trying to use this Tip on a Code Snippet Action but I am having trouble finding the ‘form’s WorkItem reference’.

    Could you please advise about how I can access the ‘the form’s WorkItem reference’ from the C# Code Snippet.

    Thanks in Advance!

    Reply
    • Safwan, from C# Snippet you dont need access to that. Just use “this.DialogService.ShowMessage(“You must first do something.”);”

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!