Importing BOM values from excel into ax

do{
ttsbegin;
row++;
NumberSeq = NumberSeq::newGetNumFromCode(BOMParameters::numRefBOMId().numberSequence);
bom.BOMId=NumberSeq.num();
bom.Name=cells.item(row,1).value().bStr();
bom.ItemGroupId=cells.item(row,2).value().bStr();
bom.SiteId=cells.item(row,3).value().bStr();
bom.insert();


type= cells.item(row+1,1).value().variantType();
ttscommit;
}

 

I'm trying to import the value into ax BOMTable, all the values got inserted except the siteId...

I checked the relations to, shall I know how to insert it from excel?

Thanks.

  • probably cell's value is numeric and your code reads empty string. you may use my method for read guarantee sited cell:

    bom.siteid = getcellfromexcel(cells.item(row,3));


    put this method to global class and change your code like up:

    public static str getCellfromExcel(SysExcelCell _cell)
    {
    Name name;
    real r;
    ;
    switch(_cell.value().variantType())
    {
    case COMVariantType::VT_BSTR:
    name = _cell.value().bStr();
    break;
    case COMVariantType::VT_DECIMAL, COMVariantType::VT_R4, COMVariantType::VT_R8:
    r = _cell.value().double();
    if (real2int(r) == r)
    name = num2str(r,0,0,1,0);
    else
    name = num2str(r,0,5,1,0);
    break;
    case COMVariantType::VT_I1, COMVariantType::VT_I2, COMVariantType::VT_I4:
    name = num2str(_cell.value().int(),0,0,0,0);
    break;
    case COMVariantType::VT_UI1, COMVariantType::VT_UI2, COMVariantType::VT_UI4:
    name = num2str(_cell.value().uLong(),0,0,0,0);
    break;
    case (COMVariantType::VT_DATE):
    name = date2str(_cell.value().date(),123,2,1,2,1,4);
    case COMVariantType::VT_EMPTY:
    name ="";
    break;
    default:
    name="";
    }

    return name;
    }
Related
Recommended