Convert Code to Integer

DarkHorseDarkHorse Member Posts: 389
Dear sirs, from Management of relations/Contacts you can create a contact like client from Action/To create like client. What I want is that when trying it verifies it if a certain interaction has been carried out looking for this in the table " Interaction Log Entry" and I put the following code:

interaccion.INIT;
IF interaccion.GET (Cont." No.") THEN;
IF interaccion." Interaction Template Code" =' 3'
THEN CreateCustomer (ChooseCustomerTemplate) ELSE ERROR: ='must send interaction 3';

interaction is the table Interaction Log Entry
Cont is the table Contact
All good, but when trying it appears to me the message " The type of the Code expression cannot become to a value Integer" and it does not let to me continue. I suppose that is because the first key from Interaction Log Entry table is a Integer one and "No." it's a Code one. How can I do it?.
Thanks in advance.
«1

Comments

  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    ContactNo --- integer

    interaccion.INIT;
    If not (Evaluate(ContactNo,Cont." No.")) then
    error('Could not convert into Integer');

    IF interaccion.GET (ContactNo) THEN;
    IF interaccion." Interaction Template Code" =' 3'
    THEN CreateCustomer (ChooseCustomerTemplate) ELSE ERROR: ='must send interaction 3';


    I hope it helps.... O:)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. I've created the ContactNo as an Integer variable and I've tried the code, but it shows me 'Could not convert into Integer'. It doesn't work; any idea please?.
    Thanks.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    the message "Could not convert into Integer" confirms that Cont." No." is not something that can be treated as Integer. Please see the value in your table.


    You are searching for the contact no in the Interaction log entry.
    so I would suggest something like....
    interaccion.INIT; 
    interaccion.Reset; 
    interaccion.SetCurrentKey("Contact No.","Correspondence Type","E-Mail Logged",Subject,Postponed);
    interaccion.SetRange("Contact No.",Cont."No.") 
    If interaccion.FindFirst THEN Begin 
      IF interaccion."Interaction Template Code" = '3' Then
        CreateCustomer (ChooseCustomerTemplate) 
      ELSE 
        ERROR('must send interaction 3'); 
    End
    Else
      message('Contact No. Doesn''t exists in Interaction Log Entry'); 
    




    I hope it helps.... O:)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • djswimdjswim Member Posts: 277
    You may also want to do a search... I remember this being a problem for me on several occasions when I did development so I have to think it's been posted here before.
    "OMG ALL MY DATA IS GONE"
    "Show All..."
    "Oh..."
  • DarkHorseDarkHorse Member Posts: 389
    Thanks. On save the code it says that don't recognize Postponed, It's a variable?.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    OR......

    interaccion.INIT;
    interaccion.Reset;
    interaccion.SetCurrentKey("Contact No.","Correspondence Type","E-Mail Logged",Subject,Postponed);

    IF interaccion.GET (Cont." No.") THEN;
    IF interaccion." Interaction Template Code" =' 3'
    THEN CreateCustomer (ChooseCustomerTemplate) ELSE ERROR: ='must send interaction 3';
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    DarkHorse wrote:
    Thanks. On save the code it says that don't recognize Postponed, It's a variable?.

    In the 5.0 Version It is a field and part of the key.
    Just comment the SetCurrentKey Part and then check if it works the same what you want. Later correct key can be set.... O:)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DarkHorseDarkHorse Member Posts: 389
    Well, the key from my version is without postponed; but I've try the code but the result it's the same, it shows me the message "The type of expression Code cannot become to a value of Integer". Finnally the code is:

    interaccion.INIT;
    interaccion.RESET;
    interaccion.SETCURRENTKEY("Contact No.","Correspondence Type","E-Mail Logged",Subject);
    IF interaccion.GET (Cont."No.") THEN;
    IF interaccion."Interaction Template Code" = '3' THEN
    CreateCustomer (ChooseCustomerTemplate)
    ELSE
    ERROR:='must send interaction 3';

    Ant idea else please; thanks you very much for your interest.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Use this version
    interaccion.INIT; 
    interaccion.Reset; 
    interaccion.SETCURRENTKEY("Contact No.","Correspondence Type","E-Mail Logged",Subject);
    interaccion.SetRange("Contact No.",Cont."No.") 
    If interaccion.FindFirst THEN Begin 
      IF interaccion."Interaction Template Code" = '3' Then 
        CreateCustomer (ChooseCustomerTemplate) 
      ELSE 
        ERROR('must send interaction 3'); 
    End 
    Else 
      message('Contact No. Doesn''t exists in Interaction Log Entry'); 
    


    The problem is with [IF interaccion.GET (Cont."No.") THEN; ] because Get works with primary key only...!!
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply, I'm sorry, but it says me before save that there is a syntactical error on the code, it stops in: If interaccion.FindFirst THEN Begin
    Thanks for everything.
  • SavatageSavatage Member Posts: 7,142
    shouldn't there be an else begin & and end?
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    DarkHorse wrote:
    syntactical error on the code, it stops in: If interaccion.FindFirst THEN Begin

    a semicolon ....!!

    interaccion.SetRange("Contact No.",Cont."No.") ;
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Savatage wrote:
    shouldn't there be an else begin & and end?

    NO, that is OK. Ideally that should be there for better readability.
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DarkHorseDarkHorse Member Posts: 389
    Well, putting semicolon says "specifies FindFirst variable", and stops on the same place;
    I'm sorry, I believe that I am bothering too much......
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Dear,

    I did following for the test
    interaccion.INIT; 
    interaccion.Reset; 
    interaccion.SetCurrentKey("Contact No.","Correspondence Type","E-Mail Logged",Subject,Postponed); 
    interaccion.SetRange("Contact No.",'CT000062');
    If interaccion.FindFirst THEN
     MESSAGE('found...')
    ELSE
     MESSAGE('Not found...')
    

    it is working for me....!!
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DarkHorseDarkHorse Member Posts: 389
    Thanks. I'll try it, I must go now but I'll say to you the result. Thanks both for help and patience
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    what is your DB version ....??
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • SavatageSavatage Member Posts: 7,142
    what is your DB version ....??
    Yes perhaps you are using an older version and need to use find instead?
  • DarkHorseDarkHorse Member Posts: 389
    Dear folks, I'¡m here again. My DB version is Attain 3.70. When I try the code it shows me that don't find FindFirst variable. Thanks for reply.
  • kinekine Member Posts: 12,562
    This command was introduced in NAV 4.00SP1. You need to use FIND('-') instead...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DarkHorseDarkHorse Member Posts: 389
    Ok, thank you. It already works. But when I do the interaction it still shows me the message 'must send interaction 3', it seems that don't go to the mov log. interaction table to see the field content.
    Thanks everybody for help.
  • DarkHorseDarkHorse Member Posts: 389
    Any help please?.
    Thanks in advance.
  • awarnawarn Member Posts: 261
    What version are you on?

    FINDFIRST will only work from 4.0 SP3 and up, if you are using earlier then use FIND('-') instead of FINDFIRST

    -a
  • DarkHorseDarkHorse Member Posts: 389
    Thanks; my version is 3.70 and I've used Find('-') and It seems to word. But when I do the interaction it still shows me the message 'must send interaction 3', it seems that don't go to the mov log. interaction table to see the field content. I think there is a problem o the following code:

    interaccion.INIT;
    interaccion.RESET;
    interaccion.SETCURRENTKEY("Contact No.","Correspondence Type","E-Mail Logged",Subject);
    interaccion.SETRANGE("Contact No.",Cont."No.");
    IF interaccion.FIND('-') THEN BEGIN
    IF interaccion."Interaction Template Code" = '3' THEN
    CreateCustomer(ChooseCustomerTemplate)
    ELSE
    ERROR('must send interaction 3');
    END;

    Thanks.
  • awarnawarn Member Posts: 261
    Try this:

    interaccion.INIT;
    interaccion.RESET;
    interaccion.SETCURRENTKEY("Contact No.","Correspondence Type","E-Mail Logged",Subject);
    interaccion.SETRANGE("Contact No.",Cont."No.");
    IF interaccion.FIND('-') THEN BEGIN
    IF interaccion."Interaction Template Code" = '3' THEN
    CreateCustomer(ChooseCustomerTemplate)
    ELSE
    ERROR(interaccion."Interaction Template Code");
    END;


    It will show you the template code for the selected record, then you can see maybe the problem.
    I may also in your error message show the primary key fields (not sure myself whatthey are for this table), maybe you are not on the record you expect.

    -a
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. It shows me another interaction, I can't find why precisely, itsn't the first interaction from this contact either the last. Well, I'll see what can I do.
    Thank you very much for help.
  • awarnawarn Member Posts: 261
    Then you need to use another key. When you say 'first interaction' - what do you mean?

    Try this - run the table, and choose the same key as is in your code and then apply the same filter as on the code.

    What record is first? I suspect the same incorrect one that you do not want to see. If you change the key to something else do you see the record you want? Or maybe your record is the last one in the list instead of the first?

    -a
  • DarkHorseDarkHorse Member Posts: 389
    Thanks for reply. I mean that there are several interactions (11,16..etc..) each interaction is a model; I want that, before the contact became a customer, the code check that the interaction 3 has been done, else it can't became a customer.
    In this case the interaction it's done, but the code go on show me the message "must send interaction 3", the record is the last one on the list; then it proves that don't check the table correctly looking for coincident values. I've check several keys and it shows me differents interactions, not what I want.
    Thanks.
  • awarnawarn Member Posts: 261
    It sounds like you want it something like this:

    interaccion.RESET;
    interaccion.SETCURRENTKEY("Contact No.","Correspondence Type","E-Mail Logged",Subject);
    interaccion.SETRANGE("Contact No.",Cont."No.");
    interaccion.SETRANGE("Interaction No.",'3'); //<- not sure of this
    IF NOT interaccion.FIND('-') THEN
    ERROR(interaccion."Interaction Template Code")
    ELSE
    CreateCustomer(ChooseCustomerTemplate);

    You probably need to use a better key, it should be Contact No., Interaction No..

    -a
  • DarkHorseDarkHorse Member Posts: 389
    Thanks; but with this code it create me the customer with or without interaction 3, it seems don't look for in the table.
    Also I've created the key, Contact No., Interaction Template Code, but the result it's the same. It's strange, i don't know what I do.
    Thank you very much for your interest.
Sign In or Register to comment.