Using Global Script functions in InforCRM

I recently had a project that required me to be able to check if a user belonged to a particular team.  A previous post by Ryan showed me how to query team membership, but rather than setting this up as a Business Rule, I wanted to create it as a Global function that could be called from anywhere without having to worry about instantiating an entity to access the business rule.

Instead of creating a business rule, I created a Global CS script to contain my function, which I could then use from anywhere. My script contains the following code:

using System;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using Dropthings.Web.Util;
using Sage.Integration.Messaging;
using Sage.Platform.Application;
using Sage.Platform.Application.Diagnostics;
using Sage.Platform.Application.UI.Web;
using Sage.Platform.Diagnostics;
using Sage.Platform.Utility;
using Sage.SalesLogix;
using log4net;
using log4net.Config;
public class FXGlobal : HttpApplication
{
    public static Boolean IsUserOnTeam(String TeamName)
    {
        bool OnTeam = false;
        
        var user = Sage.SalesLogix.API.MySlx.Security.CurrentSalesLogixUser;
        using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper())
        {
            OnTeam = 0 < Convert.ToInt32(session.CreateQuery("select count(*) from OwnerRights r where r.Owner.Type = :type and r.Owner.OwnerDescription = :teamname and r.User.Id = :accessid")
                     .SetAnsiString("type","G")
                     .SetAnsiString("teamname", TeamName)
                     .SetAnsiString("accessid", user.Id.ToString())
                     .UniqueResult());
        }
        
        if (user.Id.ToString().Trim().ToUpper() == "ADMIN")
        {
            OnTeam = true;
        }        
        
        return OnTeam;
    }
}

The using statements on the script I copied from the Existing Global.cs script.  Some of them are probably not needed for what I am doing, but it was easier to add them all in rather than taking the time to figure out what each assembly does.  You’ll note also, that the function is contained in a new Public class, which inherits from HttpApplication.

Once I created the script, called FXGlobal.cs, we have to add it to InforCRM.   The place we need to do this is in the App_Code folder under support files in the Portal Manager. (Portal Manager->Saleslogix Client->Support Files->App_Code.)  From that location, right-click the App_Code folder and select “Add Existing”.  Browse to the new CS file, and that should be it!  The script has now been added to InfoCRM.

To use this function in a code Snippet action item, for example; we just need to reference the Class Name and then the function.  From my example, this would be FXGlobal.IsUserOnTeam(“TeamName”).

That’s all there is to it!   All in all, a very simple way to create functions that are accessable throughout InforCRM.

Thanks for reading!

ABOUT THE AUTHOR

Jason Buss

Jason is a senior application developer with Customer FX.

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!