Item Dimension

Good day all and happy holidays :slight_smile:

So my coding book still hasn’t come in yet but i’m desperately trying to figure this out. I currently have a report where I am trying to print out Item Dimensions associated with the item. I found all the tables and fields that would relate but i’m weak in C/AL code. Here is what I have so far

IF SalesLine.Type=SalesLine.Type::Item THEN BEGIN
Item.GET(SalesLine.“No.”);
Default Dimension.GET(Default Dimension.“No.”);
Item.CALCFIELDS(Dimension);
END ELSE
CLEAR(ITEM):

I know the above is totally wrong… i’m having trouble trying to figure out how to code this big time what i’m trying to look for is the following

If I have a Item.“No.” -----I would like to relate it to "Default Dimension.“No.” " and GET all related "Default Dimension.“Dimension Value Code” "

Next GET FOR EACH "Default Dimension.“Dimension Value Code” " WHERE “Dimension Value Code” = "Dimension Value.“Name” "

Return "Dimension Value. “Name” "

I’m sorry if that sounds a little confusing… took me a while to get it all straight in my head, but if this was SQL i could come up with a query but it’s not and its C/AL where i’m trying to learn as much as possible but until my book gets in, google searches just aren’t cutting it. If anyone can help I will be forever in debt!

Thank you!

CALCFIELDS can only be used on FlowFields.

You need to define a record variable for the Default Dimension table and set the appropriate filters using SETRANGE or SETFILTER. You can then use the FINDSET method and a REPEAT…UNTIL loop to get all of the records. Try translating that to code and see what you can come up with.

Thanks here is what I came up with.

ItemDimVal.SETRANGE(“Default Dimension” , “Sales Line”.“No.”);

ItemDimVal.SETRANGE(“Dimension Value” , “Default Dimension”.“Dimension Value Code”);

ItemDimVal.SETRANGE(“Dimension Value” , “Dimension Value.Code”.“Name”);

^^ I think I messed that up somewhere…

IF Default Dimension.FINDSET(FALSE, FALSE) THEN BEGIN
REPEAT
ItemDimVal.“Dimension Value Code”.“Name”
UNTIL ItemDimVal.NEXT =0;
END

So when I try to compile this I get an error stating "A field from a record variable was expected. For example: Record.Field, Customer.Name

This line of code has problem, I think there should be some sort of assignment statement.

For example: A:=B; (:= is assignment operator)

yup after i posted i notice that I didn’t have any sort of assignment statement… so I tried setting ItemDimVal;=“Dimension Value Code”.“Name” but it still gives me the warning of “A field from a record variable was expected.”

So I changed up the code a bit thinking this would get it taking into account Dhan Raj Bansal observation and still received the same error :-/ …

But anyways here is what I have and im going to keep hacking away at it…

ItemDimVal.SETRANGE(“Default Dimension”.“No.” , “Sales Line”.“No.”);
ItemDimVal.SETRANGE(“Dimension Value Code” , “Dimension Value”.“Code”);

IF ItemDimVal.FINDSET THEN BEGIN
REPEAT
ItemDimVal.“Dimension Value Code” := ItemDimVal.“Dimension Value”.“Name”;
ItemDimVal.GET(“Dimension Value”.“Name”);
UNTIL ItemDimVal.NEXT =0;
END

so i got the warning to go away but nothing still show up in the report. After I set my variable to "ItemDimVal as a datatype Record and SubType to the table “Default Dimension” and my variable "Dimension Value as a datatype Record and subtype to the table Dimension Value, I began with the following code

ItemDimVal.SETRANGE(“No.” , “Sales Line”.“No.”); //Setting the range for ItemDimVal to only the No. = Sales Line.No

ItemDimVal.SETRANGE(“Dimension Value Code” , “Dimension Value”.“Code”); //Next setting field Dimension Value Code to the
// field “Code” in the Dimension Value table

//Next I run the method as the following :
IF ItemDimVal.FINDSET THEN BEGIN
REPEAT
ItemDimVal.GET(“Dimension Value”.“Name”); //Does this “GET” the NAME??? <<< if so how to output
UNTIL ItemDimVal.NEXT =0;
END;

Yet I still get nothing to show up… keep you guys posted… unless u just want me to stop and post the solution when i find it :slight_smile:

ok folks Finally came up with a soultion using multiple variables and if statements.

PM me if you want a little walk thru on how this was done… it was round about way of doing it but it works :slight_smile: