Inserting new Unit of Measure

Hello there, I am trying to insert a new unit of measure in the table Item Unit of Measure using a dataport and I cannot do it, it is stopped in 8% when it begins to insert on the table and finnaly the item is not inserted. Everything looks fine, I created the dataitem for the table and the datafields were added correctly. I am lost where is the error or if this operation can be done or not. Please, advise me and I’ll appereciate a lot. Thanks in advance.

Can you post your code for the insert?

Yes, I am posting the code is something like this: “CD-KDKDAN” | “EA” | “1” | “0” | “0” | “0” | “0” | “0”

:slight_smile: 10101001100001111000111000000001100101010111001 not really helping? Please show the code - ie → IF NOT UOM.GET(ItemNo,UOM) THEN BEGIN UOM.“Item No.” := ItemNo; ← etc. Make sure you insert the item first (with a commit) before go inserting to table UOM (since the itemno will get validated) - or just insert all data without validating (to both tables) and run a validating report later on item table.

Thanks for your advice, but I did something like that before. Look at the code: <—> IF NOT Item_Unit_Measure.GET(“Item No.”, “Item No.”) THEN BEGIN Item_Unit_Measure.INIT(); Item_Unit_Measure.“Item No.”:= “Item No.”; Item_Unit_Measure.Code := Code; Item_Unit_Measure.“Qty. per Unit of Measure” := “Qty. per Unit of Measure”; Item_Unit_Measure.Length := Length; Item_Unit_Measure.Width := Width; Item_Unit_Measure.Height := Height; Item_Unit_Measure.Cubage := Cubage; Item_Unit_Measure.Weight := Weight; Item_Unit_Measure.MODIFY(FALSE); END; <—> First I am adding the item to item table and after that when I try to insert the unit of measure, then the dataport don’t finish, it is stopped in 77% and the unit of measure is not inserted. Please, let me know what I can do …

I think you are missing the Insert. So instead of Item_Unit_Measure.Modify(False), use Item_Unit_Measure.INSERT.

I tried with: Unit_of_measure.Insert Unit_of_measure.Insert(true) and Unit_of_measure.Modify(true) and nothing works.

One thing you IF statement is wrong. Second parameter should be for Item UOM Code NOT Item No. IF NOT Item_Unit_Measure.GET(“Item No.”,Code) THEN BEGIN

Thanks for your answer, but the code is fine. I cannot compare the field Item No. with the field Code. In this case I am comparing datafield “Item No.” with the field “Item No.” in the table.

No, when you are using GET meaning you are passing the primary key fields as parameter. table “Item Unit Measure” has a primary key of “Item No.”,Code. So when you trying to get the Item UOM, you need to to pass item no. and the current UOM you are trying to create.

Ok, I undertand. I did it, but neither it didn’t work.[:(] I think some additionals tables must be modified when I want to add a new unit of measure. I need to know if any people can add a new unit of measure to the table, then how he can do it. [:)]

IF NOT Item_Unit_Measure.GET(“Item No.”, Code) THEN BEGIN //First insert the IF NOT Unit_Measure.GET(Code) THEN BEGIN Unit_Measure.INIT; Unit_Measure.Code := Code; Unit_Measure.Insert; END; //Now Insert the Item Unit of Measure. Item_Unit_Measure.INIT; Item_Unit_Measure.“Item No.”:= “Item No.”; Item_Unit_Measure.Code := Code; Item_Unit_Measure.“Qty. per Unit of Measure” := “Qty. per Unit of Measure”; Item_Unit_Measure.Length := Length; Item_Unit_Measure.Width := Width; Item_Unit_Measure.Height := Height; Item_Unit_Measure.Cubage := Cubage; Item_Unit_Measure.Weight := Weight; Item_Unit_Measure.Insert; END;

Thanks for your help. I tested this code and it didn’t work. [:(] Another hint.

What Error message are you getting? May be its because the special characters (i.e. " ) creating the problem. change the text file into TAB delimited file, then change the dataport properties FieldStartDelimiter = FieldEndDelimiter = FieldSaperator = let me know the error message.

I don’t get a message error. When the dataport is being processed it is stopped in the 71%. In my dataport, first I added my item to Item table and it is successfully inserted but after that when I try to insert the unit of measure, the dataport didn’t work.

Did you check the data in the table itself? I bet you will see the Item Unit of measure and unit of measure in the table itself. check that. Sometimes in the last dataport runs so fast that you do not notice that its done 100%.

In the Item table the items were successfully inserted, but in the item unit of measure the unit of neasure for both items were not inserted.[:(]

Are you writing code on OnBeforeImportRecord? You must write this code on the OnAfterImportRecord. Also This time, if possible write your complete code here, you I can check?

Hi, Are you sure that “Unit of Measure” table (id-204) is having all the unit of measure code which you are importing. If not then it will not?

Rajesh, During his code, Raul is inserting the UOM’s & Item UOM’s, if they do not exist. NAveen Jain