Showing posts with label Get the previous value. Show all posts
Showing posts with label Get the previous value. Show all posts

Wednesday, July 13, 2022

Get the previous value and current value If user changed any Record on form in D365FO

Hi guys, Today I got a requirement If user is changed any value in user info form that time I need to capture the previous value and current value.

For this I have created new table and I have inserting data into that table by using below class.

This class I am calling from write method in form data source.


public class UserModificationLog
{

    public static void updateLogTable(Common    _common)// This method I am calling from write method.
    {
        
        switch (_common.tableId)
        {
            case tablenum(UserInfo) :
                UserModificationLog::updateUserLog(_common);
                break;
        }
    }

    public static void updateUserLog(UserInfo    _userInfo)
    {
        DictTable   dictTable     = new sysDictTable(tableNum(UserInfo));
        //DictTable   dictTable     = new sysDictTable(_userInfo.TableId);
        fieldId     fieldId       = dictTable.fieldNext(0);         dictField   dictField;         UserInfo    userInfoOrg   = _userInfo.orig();         while(fieldId)         {             if (userInfo.(fieldId) != userInfoOrg.(fieldId))                 //|| userInfo.(fieldId) != _userInfo.orig().(fieldId))             {                 UserModifications    userModifications =                                      UserModificationLog::getUserModifications(fieldId);                 if (userModifications != UserModifications::None)                 {                     UserModificationLog::insertData(_userInfo, userInfoOrg, fieldId,                                                      dictTable.fieldObject(fieldId).name(),                                                      userModifications);                 }             }                      fieldId = dictTable.fieldNext(fieldId);         }     }     public static void insertData(Common    common, Common    orgCommon,                                     fieldId     fieldId, str fieldName,                                     UserModifications  _userModifications)     {         SecurityUserRolesLogNew roleLocation;         roleLocation.clear();         roleLocation.ModifiedByUserId           = curUserId();         roleLocation.Company                    = curExt();         roleLocation.ModifiedDateTim            = DateTimeUtil::getSystemDateTime();         roleLocation.UserId                     = _common.(fieldNum(UserInfo, id));         roleLocation.UpdatedRecord              = any2Str(_common.(_fieldId));         roleLocation.PreviousRecord             = any2Str(_orgCommon.(_fieldId));         roleLocation.UserModifications          = _userModifications;                                     //UserModificationLog::getUserModifications(_fieldId);         roleLocation.insert();     }
}


 Keep Daxing!!