Options

Programming - Try to update item journals dimensions from item card dimensions

T222T222 Member Posts: 63
Hi,

I have wrote something in order to take dimension values from item card and update the item journals . It seems that I'm doing something wrong. I have the following but I have error that Dimension set 0 already exists. Can somebody help me please? I'm trying for hours and I can't solve it.

I have 3 global variables that are the following
DefaultDimension Record Default Dimension
DimensionsetEntry Record Dimension Set Entry
TempDimensionsetEntry Record Dimension Set Entry

and my programming code is this
DefaultDimension.RESET;
DefaultDimension.SETRANGE(DefaultDimension."Table ID",27);
DefaultDimension.SETRANGE(DefaultDimension."No.","Item Journal Line"."Item No.");
IF DefaultDimension.FIND('-') THEN
REPEAT
DimensionsetEntry.INIT ;
DimensionsetEntry."Dimension Set ID" := "Item Journal Line"."Dimension Set ID";
DimensionsetEntry."Dimension Code" := DefaultDimension."Dimension Code" ;
DimensionsetEntry."Dimension Value Code" :=DefaultDimension."Dimension Value Code";

TempDimensionsetEntry.RESET;
TempDimensionsetEntry.SETRANGE("Dimension Set ID",DimensionsetEntry."Dimension Set ID");
TempDimensionsetEntry.SETRANGE("Dimension Code",DimensionsetEntry."Dimension Code");
TempDimensionsetEntry.SETRANGE("Dimension Value Code",DimensionsetEntry."Dimension Value Code");

IF NOT TempDimensionsetEntry.FIND('-') THEN
DimensionsetEntry.INSERT;

UNTIL DefaultDimension.NEXT = 0;

Answers

  • Options
    KishormKishorm Member Posts: 921
    try this...
    DefaultDimension.RESET;
    DefaultDimension.SETRANGE(DefaultDimension."Table ID",27);
    DefaultDimension.SETRANGE(DefaultDimension."No.","Item Journal Line"."Item No.");
    IF DefaultDimension.FIND('-') THEN
    REPEAT
      TempDimensionsetEntry.INIT ;
      TempDimensionsetEntry."Dimension Set ID" := "Item Journal Line"."Dimension Set ID";
      TempDimensionsetEntry."Dimension Code" := DefaultDimension."Dimension Code" ;
      TempDimensionsetEntry."Dimension Value Code" :=DefaultDimension."Dimension Value Code";
      TempDimensionsetEntry.INSERT(TRUE);
    UNTIL DefaultDimension.NEXT = 0;
    
    "Item Journal Line"."Dimension Set ID" := DimensionMgt.GetDimensionSetID(TempDimSetEntry);
    "Item Journal Line".MODIFY;
    
  • Options
    T222T222 Member Posts: 63
    Hi Kishorm, thanks for your reply.

    trying this I have an error
    Dimension set Entry already exists ....
    can you help please?

  • Options
    KishormKishorm Member Posts: 921
    1) Make sure that TempDimensionsetEntry is a temporary variable

    2) if you are calling the code in a loop add a TempDimensionsetEntry.DELETEALL; at the end of the code
  • Options
    T222T222 Member Posts: 63
    Thanks a lot Kinshorm! How can I skip the entries that already exists (some entries have dimension values) to avoid the error?
  • Options
    KishormKishorm Member Posts: 921
    T222 wrote: »
    Thanks a lot Kinshorm! How can I skip the entries that already exists (some entries have dimension values) to avoid the error?

    I not sure what you mean, please explain in more detail with example data
  • Options
    T222T222 Member Posts: 63
    if my journal doesn't have any dimension values then it works.
    however if some lines have already values then I have an error that dimension set already exists

    my code is

    IF ("Item Journal Line"."Journal Template Name" = 'PHYS. INVE') AND
    ("Item Journal Line"."Journal Batch Name" = 'LOC220') THEN
    BEGIN
    DefaultDimension.RESET;
    DefaultDimension.SETRANGE(DefaultDimension."Table ID",27);
    DefaultDimension.SETRANGE(DefaultDimension."No.","Item Journal Line"."Item No.");
    IF DefaultDimension.FIND('-') THEN
    REPEAT
    TempDimensionsetEntry.INIT ;
    TempDimensionsetEntry."Dimension Set ID" := "Item Journal Line"."Dimension Set ID";
    TempDimensionsetEntry."Dimension Code" := DefaultDimension."Dimension Code" ;
    TempDimensionsetEntry."Dimension Value Code" :=DefaultDimension."Dimension Value Code";
    TempDimensionsetEntry.INSERT(TRUE);

    UNTIL DefaultDimension.NEXT = 0;

    "Item Journal Line"."Dimension Set ID" := DimensionMgt.GetDimensionSetID(TempDimensionsetEntry);
    "Item Journal Line".MODIFY(TRUE);
    TempDimensionsetEntry.DELETEALL
    END;

  • Options
    krikikriki Member, Moderator Posts: 9,096
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.