Search This Blog

Thursday, May 8, 2014

Find Records using TableID and Recid

Finding the record of the Table if you have only tableId and Recid
I have the scenario when I import using AIF and I want to find which record and which table its imported we can find by using its messageID in the AIFCorrelation table and in that table we can find the reference record that imported using that AIFDocumentService. In that table it will store the referenceTableID and recid.

public Common findRecordOfTableID(TableId _tableId, RecId _recId, Boolean _forUpdate = false)
{
    Common      common;
    DictTable   dictTable;
    ;
    dictTable = new DictTable(_tableId);
    common = dictTable.makeRecord();

    common.selectForUpdate(_forUpdate);

    select common
    where common.RecId == _recId;

    return common;
}

//This method is used to update the table based on the tableID and recid of that table.
public void updateValueOfTableId(TableId _tableId, RecId _recId, str _field, AnyType _value)
{
    Common      common;
    Int         fieldId;
    ;
    ttsbegin;
    common = this.findRecord(_tableId, _recId, true);
    fieldId = fieldname2id(_tableId,_field);

    if (fieldId && _value)
    {
        common.(fieldId) = _value;
        common.update();
    }
    ttscommit;
}