Wednesday, January 25, 2023

How to create BCC in print management

[ExtensionOf(formstr(SRSPrintDestinationSettingsForm))]

public final class XYZSRSPrintDestinationSettingsForm_Extension

{

  public void init()

  {

    CustParameters custParameters = CustParameters::find();

    FormRun formRun = this as  FormRun;

   next init();

    //_printDestinationSettings = this.args().caller() as SRSPrintDestinationSettings;

   //SrsPrintDestinationSettings printerSettings = new SrsPrintDestinationSettings(this.parm);

   FormStringControl mailbcccontrol = formRun.design().ControlName(FormControlStr(SRSPrintDestinationSettingsForm, MailBCC));

    mailbcccontrol.text(custParameters.XYZBCCEmailAddress);

    //printerSettings.parmBCc(custParameters.XYZBCCEmailAddress);

  }

  public void closeOk()

  {

    FormRun formRun = this as  FormRun;

    next closeOk();

    FormStringControl mailbcccontrol = formRun.design().ControlName(FormControlStr(SRSPrintDestinationSettingsForm, MailBCC));

    CustParameters custParameters = CustParameters::find(true);

    if(custParameters.XYZBCCEmailAddress !=  mailbcccontrol.text())

    {

      ttsbegin;

      custParameters.XYZBCCEmailAddress = mailbcccontrol.text();

      custParameters.update();

      ttscommit;

    }

  }

}

[ExtensionOf(classStr(SRSPrintDestinationSettingsFormFormAdaptor))]

public final class XYZSRSPrintDestinationSettingsFormFormAdaptor_Extension

{

  public StringEditAdaptor MailBCC()

  {

    return this.adaptorActivateGroup("MainGroup", False).adaptorActivateGroup("RightColumn", False).adaptorActivateGroup("TargetSpecificationGroup", False).adaptorActivateTabPage("MailTab", False).adaptorActivateGroup("MailGroup", False).adaptorActivateGroup("MailDestinationGroup", False).adaptorActivateGroup("MailCCGroup", False).adaptorActivateGroup("MailCCField", False).getStringEdit("MailCC");

  }


  public GroupAdaptor MailBCCField()

  {

    return this.adaptorActivateGroup("MainGroup", False).adaptorActivateGroup("RightColumn", False).adaptorActivateGroup("TargetSpecificationGroup", False).adaptorActivateTabPage("MailTab", False).adaptorActivateGroup("MailGroup", False).adaptorActivateGroup("MailDestinationGroup", False).adaptorActivateGroup("MailCCGroup", False).getGroup("MailCCField");

  }


  public ButtonAdaptor MailBCCEdit()

  {

    return this.adaptorActivateGroup("MainGroup", False).adaptorActivateGroup("RightColumn", False).adaptorActivateGroup("TargetSpecificationGroup", False).adaptorActivateTabPage("MailTab", False).adaptorActivateGroup("MailGroup", False).adaptorActivateGroup("MailDestinationGroup", False).adaptorActivateGroup("MailCCGroup", False).getButton("MailCCEdit");

  }


  public GroupAdaptor MailBCCGroup()

  {

    return this.adaptorActivateGroup("MainGroup", False).adaptorActivateGroup("RightColumn",                 False).adaptorActivateGroup("TargetSpecificationGroup", False).adaptorActivateTabPage("MailTab",     False).adaptorActivateGroup("MailGroup", False).adaptorActivateGroup("MailDestinationGroup",         False).getGroup("MailCCGroup");

  }

}



[ExtensionOf(classStr(SrsReportEMailDataContract))]

public final class XYZSrsReportEMailDataContract_Extension

{

 // public SrsReportEMailDataContract  emailContract;

  public str emailBCc;


  [DataMemberAttribute]

   public str parmBCc(str _value = emailBCc)

  {

    emailBCc = _value;

    return emailBCc;

  }


  public void validate()

  {

    SrsReportEMailDataContract srsReportEMailDataContract = new SrsReportEMailDataContract();

    next Validate();


    if (this.parmBCc() &&

            !SysEmailDistributor::validateEmails(this.parmBCc()))

    {

      throw error(strfmt("@SYS134596", "@SYS80200"));

    }

  }


  public void removeInvalidEmails()

  {

    str parmBCcValue;


    next removeInvalidEmails();


    Set invalidEmails = new Set(Types::String);


    str getOnlyValidEmails(str emailsString)

    {

      System.Exception ex;

      container validEmails;


      if (!emailsString)

      {

        return "";

      }


      container emails = str2con(emailsString, ';');

      int i;

      for (i = 1; i <= conLen(emails); i++)

      {

        str currentEmail = conPeek(emails, i);

        if (!System.String::IsNullOrWhiteSpace(currentEmail))

        {

          try

          {

            new System.Net.Mail.MailAddress(strLRTrim(currentEmail));

            if (SysEmailDistributor::validateEmail(currentEmail))

            {

              validEmails += strLRTrim(currentEmail);

            }

            else

            {

              if (invalidEmails.in(currentEmail) < 1)

              {

                invalidEmails.add(currentEmail);

              }

            }

          }

          catch (ex)

          {

            if (invalidEmails.in(currentEmail) < 1)

            {

              invalidEmails.add(currentEmail);

            }

          }

        }

      }


      return con2Str(validEmails, ';');

    }

    ;


    parmBCcValue = getOnlyValidEmails(this.parmBCc());


    if (SrsReportEMailDataContract::autoRemoveInvalidEmailsLocal())

    {

      this.parmBCc(parmBCcValue);

    }


    if (invalidEmails && !invalidEmails.empty())

    {

      str warningMessage = 'The following emails are invalid:';

      var setEnumerator = invalidEmails.getEnumerator();

      setEnumerator.reset();

      while (setEnumerator.moveNext())

      {

        warningMessage += strFmt('%1;', setEnumerator.current());

      }


      warning(warningMessage);

    }

  }


  private static boolean autoRemoveInvalidEmailsLocal()

  {

    boolean autoRemoveInvalidEmails = false;

    SysGlobalobjectCache sgoc = new SysGlobalObjectCache();


    str scope = tableStr(SysReportAdministration);

    // Read from global cache first.

    container conSGOC = sgoc.find(scope, [SysReportAdministration::getAutoRemoveInvalidEmailsKey()]);

    if(conSGOC != conNull())

    {

      autoRemoveInvalidEmails = conPeek(conSGOC, 1);

    }

    else

    {

      autoRemoveInvalidEmails = SysReportAdministration::getAutoRemoveInvalidEmails();

      sgoc.insert(scope, [SysReportAdministration::getAutoRemoveInvalidEmailsKey()], [autoRemoveInvalidEmails]);

    }


    return autoRemoveInvalidEmails;

  }

}


[ExtensionOf(classStr(SrsReportRunMailer))]
public final class XYZSrsReportRunMailer_Extension
{
  public boolean emailReport(SrsReportEMailDataContract emailContract, System.Byte[] reportBytes, str fileName)
  {
    boolean result = false;
    result = next emailReport(emailContract, reportBytes, fileName);


    //if( mailer)
    //{
    //  var messageBuilder = new SysMailerMessageBuilder();

    //  messageBuilder.setFrom(fromAddress).setSubject(emailContract.parmSubject())
    //                      .setBody(emailContract.parmBody(strFmt("To address %1", emailContract.parmTo()) +  strFmt("CC address %1", emailContract.parmCc())))
    //                      .addAttachment(new System.IO.MemoryStream(reportBytes), fileName)
    //                      .addBcc(emailContract.parmBCc())
    //                      .addTo(emailContract.parmTo()); //added
    //  result = mailer.sendNonInteractive(messageBuilder.getMessage());

    //}

    return result;
  }

}



No comments:

Post a Comment

Build Explained

Useful Blogs. https://axtechsolutions.blogspot.com/2018/08/performing-builds-in-d365.html https://community.dynamics.com/blogs/post/?postid=...