• How to using X++ code achieve copying records


    This X++ Code Snippet post describes how you can easily copy records by running over all of the fields of the from-record. During this looping over all the fields, you can exclude some fields if needed. 

     

    Create following method in a class: Jimmy_Global

    static void Jimmy_CopyoingField(Common _from, Common _to)
    {
        DictTable           t;
        DictField           f;
        
    int                 i;
        fieldId             id;
        FieldName           fieldname;
    ;
        t 
    = new DictTable(_to.TableId);
        
    if (t)
        {
            
    for (i = 1; i <= t.fieldCnt(); i++)
            {
                id 
    = t.fieldCnt2Id(i);
                f  
    = new DictField(_to.TableId,t.fieldCnt2Id(i));
                
    // excluding system fields (or add other fields to exclude during the copy action
                if (f && !f.isSystem())
                {
                    _to.(id) 
    = _from.(id);
                }
            }
        }
    }

    To copy for example a VendTable to a new one, just call your class like this:

    YourClass::CopyFields(VendTable , VendTableTo);

    VendTableTo.insert();

  • 相关阅读:
    04:求整数的和与均值
    03:均值
    02:财务管理
    C8-3 三角形还是长方形? (100/100 分数)
    C8-2 圆的周长和面积 (100/100 分数)
    C8-1 复数加减乘除 (100/100 分数)
    C7-3 用类实现a+b (100/100 分数)
    C7-2 多继承 (100/100 分数)
    C7-1 账户类(100/100)
    数组第k小数
  • 原文地址:https://www.cnblogs.com/Fandyx/p/2126967.html
Copyright © 2020-2023  润新知