I am creating a data import function in which Values should be added to several Tables and Fields in Navision Attain 3.60. Debugging the function shows that the Values are added correctly to the RecordRef Field. But the record added to the table only contains the Primary Key. The Field Value has not been updated. Here is the code: CASE “Table No.” OF DATABASE::“Daily registration”: BEGIN DailyRegistration.Date := “Capture Date” - 1; DailyRegistration.“Location Code” := “Location Code”; IF NOT DailyRegistration.FIND() THEN DailyRegistration.INSERT; RecRef.GETTABLE(DailyRegistration); UpdateField(RecRef,“Field No.”,“Capture Value”); END; etc… END; Procedure: UpdateField(RecRef : RecordRef;FieldNumber : Integer;NewValue : Variant) FldRef := RecRef.FIELD(FieldNumber); CASE TRUE OF FldRef.VALUE.ISINTEGER: FldRef.VALUE(ROUND(NewValue,1)); FldRef.VALUE.ISDECIMAL: FldRef.VALUE(NewValue); END; FldRef.VALIDATE; RecRef.MODIFY; Can anybody give a hint. Best Regards, Steen Fisker
This works in a report… tried both finding first location, and the (present code) creating a new post… Is it something in the area of Dataport without Commit() in OnPostDataport() ? (How in heaven did u find this “*.ISINTEGER” out? hehe… not listed in F5 at my system, but I guess a Variant is a Variant )
OnInitReport() OnPreReport() //Location.FIND('-'); Location.INIT(); Location.Code := 'Test'; IF Location.INSERT() THEN; RecRef.GETTABLE(Location); UpdateField(RecRef,Location.FIELDNO(Name),'Test'); OnPostReport() OnCreateHyperlink(VAR URL : Text[1024]) OnHyperlink(URL : Text[1024]) UpdateField(RecRef : RecordRef;FieldNumber : Integer;NewValue : Variant) //UpdateField(RecRef : RecordRef;FieldNumber : Integer;NewValue : Variant) FldRef := RecRef.FIELD(FieldNumber); CASE TRUE OF FldRef.VALUE().ISINTEGER(): FldRef.VALUE(ROUND(NewValue,1)); FldRef.VALUE().ISDECIMAL(): FldRef.VALUE(NewValue); FldRef.VALUE().ISTEXT(): FldRef.VALUE(NewValue); END; FldRef.VALIDATE(); MESSAGE(FORMAT(FldRef.VALUE())); RecRef.MODIFY(); MESSAGE(FORMAT(FldRef.VALUE()));
I have solved the problem. I should value-transfer RecRef to the Procedure for field update. I should leave it as global variable. So the code now looks like this: CASE “Table No.” OF DATABASE::“Daily registration”: IF NOT DailyRegistration.GET(“Capture Date” - 1,“Location Code”) then begin DailyRegistration.INIT; DailyRegistration.Date := “Capture Date” - 1; DailyRegistration.“Location Code” := “Location Code”; DailyRegistration.INSERT; END; RecRef.GETTABLE(DailyRegistration); UpdateField(“Field No.”,“Capture Value”); RecRef.MODIFY; END; etc… END; Procedure: UpdateField(FieldNumber : Integer;NewValue : Variant) FldRef := RecRef.FIELD(FieldNumber); FldValue := FldRef.VALUE CASE TRUE OF FldVALUE.ISINTEGER: FldRef.VALUE(ROUND(NewValue,1)); FldVALUE.ISDECIMAL: FldRef.VALUE(NewValue); END; FldRef.VALIDATE; This works correctly. The value tests ISINTEGER, ISDECIMAL, a.o are used in Codeunit 423 Change Log Management, Local Procedure HasValue(Value : Variant) : Boolean Steen