Run report and send thru email attachment – Dynamics 365 for Finance and Operations

In Dynamics 365 we use SysMailerFactory class to send an email thru X++ code,

Below is the code to send an email with the attachment. You can comment the attachment code if you want only to send an email thru X++

//Define variables

Filename fileName = “AbcTest.pdf”;
SrsReportRunController controller = new SrsReportRunController();
ReportContractClass contract = new ReportContractClass();
SRSPrintDestinationSettings settings;
Array arrayFiles;
System.Byte[] reportBytes = new System.Byte[0]();
SRSProxy srsProxy;
SRSReportRunService srsReportRunService = new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
Map reportParametersMap;
SRSReportExecutionInfo executionInfo = new SRSReportExecutionInfo();

//Pass contract variables
contract.parm1(); //Some contract class method for parameter
contract.parm2(); //Some contract class method for parameter

//Controller class for the report name and set contract class for controller

controller.parmArgs(_args);
controller.parmReportName(ssrsReportStr(); // Report name and design
controller.parmShowDialog(false);
controller.parmLoadFromSysLastValue(false);
controller.parmReportContract().parmRdpContract(contract);

// Provide printer settings
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileName(fileName);
settings.fileFormat(SRSReportFileFormat::PDF);

// Below is a part of code responsible for rendering the report
controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
controller.parmReportContract().parmReportExecutionInfo(executionInfo);

srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
srsReportRunService.preRunReport(controller.parmreportcontract());
reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);

srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
// Actual rendering to byte array
reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),parameterValueArray,settings.fileFormat(),settings.deviceinfo());

// You can also convert the report Bytes into an xpp BinData object if needed
container binData;
Binary binaryData;
System.IO.MemoryStream mstream = new System.IO.MemoryStream(reportBytes);
binaryData = Binary::constructFromMemoryStream(mstream);
if(binaryData)
{
binData = binaryData.getContainer();
}

System.Byte[] binData1;
System.IO.Stream stream1;

// Turn the Bytes into a stream
for(int i = 0; i < conLen(binData); i++)
{
binData1 = conPeek(binData,i+1);
stream1 = new System.IO.MemoryStream(binData1);
}

var mail = SysMailerFactory::getNonInteractiveMailer();
var messageBuilder = new SysMailerMessageBuilder();
// for (i = 1; i <= conLen(_notifyCon); i++)
// {
// notifyEmailsStr = conPeek(_notifyCon, i);
// select firstonly RecId, Email from sysUser where sysUser.Id == notifyEmailsStr;
// if (sysUser.RecId && sysUser.Email != ”)
//{
messageBuilder.reset()
.setFrom(‘from email address’)
.addTo(‘to email address’)
.setSubject(‘Email Subject’)
.setBody(‘Email Body’);

if (stream1 != null)
{
messageBuilder.addAttachment(stream1,’abcd.pdf’);
}
mail.sendNonInteractive(messageBuilder.getMessage());

Analytics reports are not updated – Dynamics 365 for Talent

Problem

Data changes don’t appear on the Analytics tabs of any of the Analytics workspaces.

Reason

MS Power BI reports are refreshed every four hours, Default schedule of the Deploy measurement batch job.

Resolution

The issue is only related to the timing of the batch job. Just follow the below steps to reduce the batch job time from 4 hours to 1 hour or as per requirement.

System administration > Links > Batch jobs > Batch jobs.
Find the Deploy measurement job in the list.
Select Edit and set the scheduled start date/time to a value that will refresh the analytics.

Backup and restore – Dynamics 365 for Talent

Microsoft Dynamics 365 for Talent backup and restore can be done from the Dynamics 365 Administration Center. Steps to take backup and restore

  1. Login to dynamics 365 Administration center
  2. Click on backup and restore tab
  3. select the instance from the dropdown Backups for:
  4. Click New backup

Backup will start and takes few minutes to complete depend on the database size

To restore the backup to the instance repeat the step 1 and 2 and then

  1. select the  backup from the list you want to restore and click on restore appearing on the right side.

Override form control lookup – Dynamics 365 Finance and Operations

To overrie the string control use SysTableLookup sysTableLookup;

To override the reference group control use SysReferenceTableLookup sysReferenceTableLookup;

Below is the example of reference control

[FormControlEventHandler(formControlStr(HcmDiscussionNewDialog, HcmDiscussion_PerfPeriod), FormControlEventType::Lookup)]
public static void HcmDiscussion_PerfPeriod_OnLookup(FormControl sender, FormControlEventArgs e)
{
SysReferenceTableLookup sysReferenceTableLookup;
Query query = new Query();

sysReferenceTableLookup =SysReferenceTableLookup::newParameters(tableNum(HcmPerfPeriod),sender);
sysReferenceTableLookup.addLookupfield(fieldNum(HcmPerfPeriod,PerfPeriodId));
sysReferenceTableLookup.addLookupfield(fieldNum(HcmPerfPeriod,StartDate));
sysReferenceTableLookup.addLookupfield(fieldNum(HcmPerfPeriod,EndDate));

sysReferenceTableLookup.parmQuery(query);
sysReferenceTableLookup.performFormLookup();

//Cancel the super

FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

ce.CancelSuperCall();

}

Validation on update/Insert/delete record – Dynamics 365 for Finance and Operations

These are four events on a table-level to validate the record. This method calls during the default insert/Update method calling.

OnfinaldeleteValidation,

OnFinalUpdateValidation,

OnfinalInsertValidation,

OnfinalReadValidation .

 

Examle:

 

/// <summary>
///
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
[DataEventHandler(tableStr(HcmTopicComment), DataEventType::FinalUpdateValidation)]
public static void HcmTopicComment_onFinalUpdateValidation(Common sender, DataEventArgs e)
{
//Custom condition to validat

throw Error(‘update not allowed’);

}