Find() Method in X++

How to write Find() Method :

static AX_Student find(AX_StudentID   _studentId,
                                       boolean       _forUpdate = false)
{
    AX_Student  newStudent;

    if (_studentId)
    {
        if (_forUpdate)
        {
            newStudent.selectForUpdate(_forUpdate);
        }

        select firstonly newStudent
            index hint StudentId
            where newStudent.AX_StudentID == _studentId;
    }

    return newStudent;
}

you can also add more parameters in Find Method.

static AX_StudentCourse find(AX_StudentID   _studentId, AX_CourseId _courseId,
                                       boolean       _forUpdate = false)
{
    AX_StudentCourse  newStudent;

    if (_studentId, _courseId)
    {
        if (_forUpdate)
        {
            newStudent.selectForUpdate(_forUpdate);
        }

        select firstonly newStudent
            //index hint StudentId            where newStudent.AX_StudentID == _studentId
                      && newStudent.AX_CourseId == _coourseId;
    }

    return newStudent;
}

Comments

Popular posts from this blog

Exporting AX Data to .csv File Through Class (Dialog)

Export Model Store (AXUtil) - ax 2012

How to add select button for query form on a class