Automated Dimension

tazzy30tazzy30 Member Posts: 52
Hello all,

I seem to have run into a bit of a pickle with automating dimensions. When a new customer is added I have inserted some code to automatically insert a 'Customer' Dimension, which works fine. However when I try to insert another Dimension ('Resource') which should be equal to the 'Salesperson Code', it returns an error message. The Dimension 'Resource' does have values which are salesperson codes, not sure how I go about adding the dimension so that when a salesperson code is added on the customer card the 'Resource' dimension equal to Salesperson Code is added. The code I have inserted is as follows:

DimValue.INIT;
DimValue."Dimension Code" := 'RESOURCE';
DimValue.Code := Customer."Salesperson Code";
DimValue.INSERT;

DefaultDim.INIT;
DefaultDim."Table ID" := 18;
DefaultDim."No." := "No.";
DefaultDim."Dimension Code" := 'RESOURCE';
DefaultDim."Dimension Value Code" := "Salesperson Code";
DefaultDim."Value Posting" := DefaultDim."Value Posting"::"Code Mandatory";
DefaultDim.INSERT;

Any ideas please?

Answers

  • AlbertvhAlbertvh Member Posts: 516
    Hi,
    Where have you put this code?
    Should be OnValidate of Sales Person Code field of the Customer Table
    also add
    IF "SalesPerson Code" <> '' THEN BEGIN
    your coding goes here
    END;

    Hope this helps

    Albert
  • DaveTDaveT Member Posts: 1,039
    Hi,

    An easier way is to set-up the dimension against the salesperson code and it will be inherited on sales transactions.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • tazzy30tazzy30 Member Posts: 52
    Thank you Albert for your reply i had the code within the Salesperson Code trigger and added your code but still no luck. I get the following error message:
    The Dimension Value already exists
  • DaveTDaveT Member Posts: 1,039
    Hi,

    You are inserting into the dimension value table each time which is a master table. Check if the value exist first before insert.
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • tazzy30tazzy30 Member Posts: 52
    Thank you Dave for your reply, would i need to change the code so instead of inserting it finds the value then inserts, because I want it to find the value from that master table and match it to the salesperson code inserted on the customer card, and if the salesperson code is changed the resource dimension is also updated?
  • DaveTDaveT Member Posts: 1,039
    Hi,

    This is the reason I recommend using the dimension on the salesperson. To operate this the resource dimension is setup against the salesperson and then when the customer is selected on a sales order for example the resource dimension is then added to the order. This will also solve the problem you will hit, that if the user changes the salesperson on the card then you will need to rewrite the default dimension value.

    Anyway the code you would need is
    if not DimValue.get( 'RESOURCE', Customer."Salesperson Code" ) then
      begin
        DimValue.INIT;
        DimValue."Dimension Code" := 'RESOURCE';
        DimValue.Code := Customer."Salesperson Code";
        DimValue.INSERT;
      end;
    
    

    Also an interesting discussion on dimensions you might find useful.

    viewtopic.php?f=23&t=29747
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • tazzy30tazzy30 Member Posts: 52
    Your absolutely right in what you had said first, applying the resource dimension to the salesperson, wasn't sure whether that would have changed the dimension as well if changed on an order, but it does.

    Thank You for taking the time to answer my question much appreciated.
  • DaveTDaveT Member Posts: 1,039
    Glad to help :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.