I have created a custom student table and through excel i have imported the data, so now when i update the data from excel in the custom field the count value should increase once i update the record in SQL, using modified field method.
First of all, which version of AX is it about? You added tags for AX 2009, AX 2012 and D365, but there are significant differences between these versions.
How are you importing the data?
Are you saying that you want to increment the value when a record is created or update by your code but not when data is modified by any other means, including the standard ways to import data? If so, why don’t you simply do it in code. The title says that you’re using X++ to do the import, therefore you have code to adjust.
I have no idea why you require doing it in modifiedField().
I am using microsoft d365 F&O , I do not know if i require modified field but if i have to add another field in the table such that if i update the records that field should get incremented, example in student table the field student count should get incremented when the record is updated.
OK, please answer my other questions, so I (and others) can understand what you actually need. We can’t give you a technical solution without knowing what it should do.
I’ll fix the version tags for you. Please be more careful with them next time, because it’s a critical piece of information.
thanks for the advice and about this, " Are you saying that you want to increment the value when a record is created or update by your code but not when data is modified by any other means, including the standard ways to import data? If so, why don’t you simply do it in code". How do I do it in the code?
Using System.IO;
Using OfficeOpenXml;
Using OfficeOpenXml.ExcelPackage;
Using OfficeOpenXml.ExcelRange;
class SIN_StudentTableRecords
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
System.IO.Stream stream;
ExcelSpreadsheetName sheet;
FileUploadBuild fileUpload,fileUploadBuild;
DialogGroup dialogUploadGroup;
SIN_StudentDetailsList studentList;
SIN_StudentId studentId;
SIN_StudentName studentName;
SIN_StudentBranch studentBranch;
SIN_StudentCgpa studentCgpa;
FormBuildControl formBuildControl;
Dialog dialog=new Dialog("Excel Import Example");
dialogUploadGroup=dialog.addGroup("@SYS54759");
formBuildControl=dialog.formBuildDesign().control(dialogUploadGroup.name());
fileUploadBuild=formBuildControl.addControlEx(classStr(fileUpload),"UploadExcel");
fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
fileUploadBuild.fileTypesAccepted(".xlsx");
if(dialog.run() && dialog.closedOk())
{
FileUpload fileUploadControl=dialog.formRun().control(dialog.formRun().controlId("Upload"));
FileUploadTemporaryStorageResult
fileUploadResult=file::GetFileFromUser(classStr(FileUploadTemporaryStorageStrategy));
//fileUploadResult=fileUploadControl.getFileUploadResult();
if(fileUploadResult!= null && fileUploadResult.getUploadStatus())
{
stream=fileUploadResult.openResult();
using(ExcelPackage package= new ExcelPackage(stream))
{
int rowCount, iterator;
package.Load(stream);
ExcelWorksheet worksheet= package.get_workbook().get_worksheets().get_Item(1);
OfficeOpenXml.ExcelRange range=worksheet.Cells;
rowCount = worksheet.Dimension.End.Row - worksheet.Dimension.Start.Row + 1;
for(iterator=2;iterator<=rowCount;iterator++)
{
studentList.SIN_StudentId = range.get_Item(iterator, 1).Value;
studentList.SIN_StudentName = range.get_Item(iterator, 2).Value;
studentList.SIN_StudentBranch = range.get_Item(iterator, 3).Value;
str cgpaStr = range.get_Item(iterator, 4).Value;
// Attempt to convert the string to a real
if (str2num(cgpaStr))
{
// Conversion successful, assign the real value to SIN_StudentCgpa
studentList.SIN_StudentCgpa = str2num(cgpaStr);
}
else
{
// Handle the case where the conversion fails, e.g., log an error or set a default value
//// For now, let's set a default value of 0.0
studentList.SIN_StudentCgpa = str2num(cgpaStr);
}
studentList.clear();
studentList.SIN_StudentId = studentId;
studentList.SIN_StudentName = studentName;
studentList.SIN_StudentBranch = studentBranch;
studentList.SIN_StudentCgpa = str2num(cgpaStr);
studentList.insert();
}
}
}
}
else
{
Error("error occured.");
}
}
}
I have used this code for excel import using X++
Are you implying that your answer to the first question is “yes”? It would help a lot if you gave us necessary information when requested (when you didn’t do it on your own).
You know what? It’ll be the best if you explained the business requirement to us. It should clarify a few things.
My requirement is that I want to establish a basic table named “Student Table,” populate it with student records using X++ code by importing data from an Excel file, and then introduce a new field that tracks the count of student records. This count should be updated every time a new record is added or modified in Dynamics 365 Finance and Operations.
“This count should be updated every time a new record is added or modified” is something completely different than what you said before. Please confirm that all the remarks about imports from Excel are irrelevant and can be ignored, because you’re interested in all changes, not just those done through import from Excel.
yes remarks about imports from Excel are irrelevant and can be ignored.
Use update() method to increment the value every time when a record is updated.
If you want to set the value to 1 on insert, you can utilize insert() method, or maybe initValue().
Your original requirement was complete wrong and you focused on code irrelevant to your actual problem (because it’s not about import from Excel). As you see, knowing what you want to achieve is absolutely critical; you need to think carefully about it before trying to writing code.