Create External DLL for BPM

Dear Experts, How to create and call a function from custom DLL in BPM. What references are required for custom DLL. Any help would be greatly appreciated !!

I have created one class library using VS2012 as mentioned in below link


While trying to build the solution system is throwing some references issues reffered to attached screenshot

Please suggest which references need to be add?

Try below code and update it accordingly your requirement.

image

using System;
using System.Linq;
using Epicor.Hosting;
using Erp;
using Ice;
using Epicor.Customization.Bpm;
using System.Globalization;
using System.Data;
using Epicor.Data;
using System.Text;

namespace Stcl.Bpm.Po
{
public partial class PO : ContextBoundBase
{
private static Erp.ErpContext IceDtContext = null; // dataContext;
public PO(ErpContext ctx) : base(ctx)
{
IceDtContext = ctx;
}

    public void CloseRelease(
        ref System.Int32 PoNum,
        ref System.Int32 PoLine,
        ref System.Int32 PoRelease,
        Erp.Tablesets.POTableset result)
    {
        try
        {
            throw new BLException("PO Entry > CloseRelease: Releases cannot be closed individually.");
        }
        catch (Exception ex)
        {
            throw new BLException("PO Entry > CloseRelease : " + ex.Message.ToString());
        }
    }
}

}

I have added same code but reference error is coming refer to below screen

It should work!.

Did you add references in the project reference folder?

Epicor.Hosting namespace belongs to the Epicor.ServiceModel assembly and Erp namespace belongs to the Erp.Data.910100 assembly, likewise you have to add other references too.

I am trying to add the references but no dll files are showing such kind of names like
ERP
Ice
Epicor.Customization.BPM
Epicor.Data.910100

what is the right path or could you please share these dll files?

Use this path and below references
C:\inetpub\wwwroot\ERPTest5\Server\Assemblies
AND
C:\inetpub\wwwroot\ERPTest5\Server\Bin

image

Thanks @priteshe for your support.

Hi Pritesh, I have written below mentioned code in external dll, while building the solution system is throwing error

using System;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.ServiceModel;
using Epicor.Data;
using Epicor.Hosting;
using Ice.Contracts;
using Ice.ExtendedData;
using Ice.Lib;
using Ice.Tables;
using Ice.Tablesets;
using Erp;
using System.Text;

namespace BpmCustomCode
{
public class POApproval
{
private Erp.ErpContext dataContext;

    public POApproval(Ice.IceDataContext context)
    {
        this.dataContext = (Erp.ErpContext)context;
    }

    public void ChangeApproveSwitch(ref System.Boolean ApproveValue, ref System.String ViolationMsg, Erp.Tablesets.POTableset ds, Ice.Tablesets.ContextTableset context)
    {
        var UD06DataSet = new Ice.Tablesets.UD06Tableset();
        var objSession  = new Ice.Core.Session();

        Ice.Contracts.UD06SvcContract hUD06 = null;
        int iCount = 0;
        string sDispMsg = string.Empty;

        var ttPOHeader_Row = (from ttPOHeader_R in ttPOHeader select ttPOHeader_R).FirstOrDefault();
        if (ttPOHeader_Row != null && ApproveValue)
        {
            string sPONum = ttPOHeader_Row.PONum.ToString();
            string sPOType = ttPOHeader_Row.POType.ToString();

            int iUD06Count = (from UD06_R in Db.UD06 where UD06_R.Company == objSession.CompanyID && UD06_R.Key1 == sPONum select UD06_R).Count();
            if (iUD06Count > 0)
            {
               foreach (var UD06_xRow in (from UD06_R in Db.UD06 where UD06_R.Company == objSession.CompanyID && UD06_R.Key1 == sPONum orderby UD06_R.Number02 select UD06_R))
               if (UD06_xRow != null)
               {
                    var UD06_Row = UD06_xRow;
                    iCount = iCount + 1;

                    UD06_Row.ShortChar01 = "";
                    UD06_Row.Date03 = DateTime.Today; // Updated Date
                    UD06_Row.Date02 = null;
                    UD06_Row.Number01 = ttPOHeader_Row.DocTotalOrder;

                    if (iCount == 1)
                    {
                       UD06_Row.CheckBox01 = true;
                       SendEmail();
                       sDispMsg = string.Format("You have exceeded your purchasing limit of {0}. This will require approval from: {1}", UD06_Row.Number02.ToString("0.00"), UD06_Row.Character02);
                    }
                }
            }
        }
    }



    public void SendEmail()
    {
        var mailer = this.GetMailer(async: true);
        var message = new Ice.Mail.SmtpMail();
        message.SetFrom("abc.def@gmail.com.net");
        StringBuilder mailBody = new StringBuilder();
        mailBody.AppendFormat("Dear User,<br /><br />");
        mailBody.AppendFormat("Please approve the Purchase Order<br /><br />");
        mailBody.AppendFormat("<table style='border: 1px solid black; border-collapse: collapse;'>");
        mailBody.AppendFormat("<tr><th style='border: 1px solid black; border-collapse: collapse;'>PONum &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Date &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>ProjectID &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Amount &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Comment &nbsp;&nbsp;</th></tr>");
        message.SetTo("abc.def@gmail.com.net");
        message.SetSubject("Approve Purchase Order");
        mailBody.AppendFormat("</table><br/><br/>");
        mailBody.AppendFormat("<p>Thanks & Regards,<br/>XYZ</p>");
        message.Body = mailBody.ToString();
        message.IsBodyHtml = true;
        mailer.Send(message);
    }
}

}

Error 1: The name ‘ttPOHeader’ does not exist in the current context
Error 2: The name ‘Db’ does not exist in the current context
Error 3: An object reference is required for the non-static field, method, or property ‘Epicor.Hosting.Session.CompanyID.get’
Error 4: ‘BpmCustomCode.POApproval’ does not contain a definition for ‘GetMailer’

@Hari_Dutt if you can wait until 10.2.500 where Epicor Functions are introduced, you don’t need to start creating External BPMs if you havent up to this point in 10.2.500 you can make a Function and call it from everywhere. Id recommend waiting, if you dont already have Externals – perhaps even plan an Upgrade in the next few weeks.

1 Like

@Hari_Dutt,

I have corrected code

using Epicor.Hosting;
using Erp;
using Ice;
using System;
using System.Data;
using System.Linq;
using System.Text;

namespace BpmCustomCode
{
public class POApproval : ContextBoundBase
{
private static Erp.ErpContext IceDtContext = null; // dataContext;
public POApproval(ErpContext ctx) : base(ctx)
{
IceDtContext = ctx;
}

    public void ChangeApproveSwitch(ref System.Boolean ApproveValue, ref System.String ViolationMsg, Erp.Tablesets.POTableset ds, Ice.Tablesets.ContextTableset context)
    {
        var UD06DataSet = new Ice.Tablesets.UD06Tableset();
        //var objSession = new Ice.Core.Session();

        Ice.Contracts.UD06SvcContract hUD06 = null;
        int iCount = 0;
        string sDispMsg = string.Empty;

        var ttPOHeader_Row = (from ttPOHeader_R in ds.POHeader select ttPOHeader_R).FirstOrDefault();
        if (ttPOHeader_Row != null && ApproveValue)
        {
            string sPONum = ttPOHeader_Row.PONum.ToString();
            string sPOType = ttPOHeader_Row.POType.ToString();

            int iUD06Count = (from UD06_R in Db.UD06 where UD06_R.Company == Session.CompanyID && UD06_R.Key1 == sPONum select UD06_R).Count();
            if (iUD06Count > 0)
            {
                foreach (var UD06_xRow in (from UD06_R in Db.UD06 where UD06_R.Company == Session.CompanyID && UD06_R.Key1 == sPONum orderby UD06_R.Number02 select UD06_R))
                    if (UD06_xRow != null)
                    {
                        var UD06_Row = UD06_xRow;
                        iCount = iCount + 1;

                        UD06_Row.ShortChar01 = "";
                        UD06_Row.Date03 = DateTime.Today; // Updated Date
                        UD06_Row.Date02 = null;
                        UD06_Row.Number01 = ttPOHeader_Row.DocTotalOrder;

                        if (iCount == 1)
                        {
                            UD06_Row.CheckBox01 = true;
                            SendEmail();
                            sDispMsg = string.Format("You have exceeded your purchasing limit of {0}. This will require approval from: {1}", UD06_Row.Number02.ToString("0.00"), UD06_Row.Character02);
                        }
                    }
            }
        }
    }



    public void SendEmail()
    {
        var mailer = this.GetMailer(async: true);
        var message = new Ice.Mail.SmtpMail();
        message.SetFrom("abc.def@gmail.com.net");
        StringBuilder mailBody = new StringBuilder();
        mailBody.AppendFormat("Dear User,<br /><br />");
        mailBody.AppendFormat("Please approve the Purchase Order<br /><br />");
        mailBody.AppendFormat("<table style='border: 1px solid black; border-collapse: collapse;'>");
        mailBody.AppendFormat("<tr><th style='border: 1px solid black; border-collapse: collapse;'>PONum &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Date &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>ProjectID &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Amount &nbsp;&nbsp;</th><th style='border: 1px solid black; border-collapse: collapse;'>Comment &nbsp;&nbsp;</th></tr>");
        message.SetTo("abc.def@gmail.com.net");
        message.SetSubject("Approve Purchase Order");
        mailBody.AppendFormat("</table><br/><br/>");
        mailBody.AppendFormat("<p>Thanks & Regards,<br/>XYZ</p>");
        message.Body = mailBody.ToString();
        message.IsBodyHtml = true;
        mailer.Send(message);
    }
}

}

image

Thanks Pritesh for your support, I have tried same as mentioned above but getting some error attached screenshot

Code.txt (3.9 KB)

change to

image