tags:

views:

239

answers:

2

When I store a RecId in an anytype object, the number is corrupted. In my implementation, I am storing the RecId in a treeview item's data value field. Whenever I retrieve the data value, the number I saved is always greatly changed. Any suggestions?

Here is an example:

void fillTree()
{
    ABC_Menus _ABC_Menus;
    TreeItemIdx parentItemIdx;
    ;
    while select Prompt, RecId from _ABC_Menus
    {
        parentItemIdx = SysFormTreeControl::addTreeItem(formTreeControl, _ABC_Menus.Prompt, FormTreeAdd::Root, _ABC_Menus.RecId, 0, true);
    }
}

public void endLabelEdit(int _idx, str _text, anytype _data)
{
    FormTreeItem formTreeItem = this.getItem(_idx);
    ;
    formTreeItem.text(_text);
    this.setItem(formTreeItem);
    info(_data);     //this number comes out all wrong
    super(_idx, _text, _data);
}

I am storing the RecId in the tree value field. However, if I retrieve it later, a totally different number comes back out.
- RecId in table: 5637144588
- RecId displayed by the endLabelEdit method: 202520592908288

I also tried using num2str(ABC_Table.RecId, 0, 0, 0) when storing the RecId in the field. When stored that way, the number matches, but an "Assignment/Comparison loses precision" warning is thrown. Is that ok, or is there a better way?

Thanks

A: 

Please provide us full example:

RefRecId   recid = 5637144577;
anytype    tmp;
;
info(strfmt('%1', recid));
tmp = recid;
info(strfmt('%1', tmp));
recid = tmp;
info(strfmt('%1', recid));

The result is:

5637144577

5637144577

5637144577

demas
If I use strfmt(...) as in your example before posting the RecId to the anytype field, the data remains uncorrupted. This solves my problem, but I'm going to leave the question open for a bit in order to hopefully learn WHY the RecId gets screwed up when posted to my anytype field. It seems you shouldn't have to convert it to a string to work. Thanks!
Brad
Try to pack recId to container or a class. Insteed of num2str you can use strfmt to avoid warning.
demas
+1  A: 

After version 3 of Axapta all RecIds are 64 bit integers. The strFmt() function is able to cast the recId from int64 to string for you, but you can also use the int642str() function to explicitly cast the recId to string.

RecId recId = 5637144577;
anytype a;
int64 b;
;

a = recId;
b = a;

info(int642str(a));
info(int642str(b));
info(int642str(recId));
Velislav Marinov

related questions