Search code examples
dynamics-ax-2012x++

Insert multiple rows in table with a join


I am trying to fill TablA, based on a Join and a certain criteria on the joining table, I have tried the following 2 jobs based on some examples i have found. But I'm not sure how to fill the table, while keeping the Job simple.

I have tried the following jobs, but both give me a syntax error:

static void AddDescription(Args _args)
{

TableA        tableA;
InventTable       inventTable;
str               info;
;
ttsBegin;



insert_recordSet tableA
setting
tableA.ItemId = inventTable.ItemId;
tableA.Description = 'DescriptionHere';
join ItemId from inventTable
where TableA.ItemId == inventTable.ItemId &&
where CriteriaA == CriteriaValueA;

tableA.insert();

ttsCommit;

    info("Done!");
}

I also have tried the following job:

static void AddDescription(Args _args)
{

TableA        tableA;
InventTable       inventTable;
str               info;
;
ttsBegin;


insert_recordSet tableA
join ItemId from inventTable
where CriteriaA == CriteriaValueA;

tableA.ItemId = inventTable.ItemId;
tableA.Description = 'DescriptionHere';

tableA.insert();

ttsCommit;

    info("Done!");
}

Obviously I'm missing a big step, can anyone give me a direction to finish this job?


Solution

  • Your syntax isn't right. Check the documentation on the function, as it's pretty comprehensive and has many samples: https://msdn.microsoft.com/en-us/library/aa635694.aspx?f=255&MSPPError=-2147217396

    Here is one sample that might be relevant to you:

    INSERT_RECORDSET tabEmplProj5
        (
        Description
        , EmployeeRecId
        , ProjectRecId
        )
    Select
        sDescriptionVariable
        , RecId
    from
        tabEmpl3
        join
            tabDept2
            where tabEmpl3 .DepartmentGuid == tabDept2 .DepartmentGuid
        join RecId
            from tabProj4
            where tabDept2 .DepartmentGuid == tabProj4 .DepartmentGuid
    ;