Startsession - Stopsession NAV

juanbo82juanbo82 Member Posts: 8
Hi!

I have a problem with STARTSESSION. I'm going to try to explain. I have a code with next structure in CU5000 (ChangeComapyT is a table that i've create)

CU50000:
.
.
SalesHeader.INSERT;
.
.
ChangeCompanyT.INSERT;

OK := STARTSESSION(SessionEvent."Session ID", CODEUNIT::ChangeCompany, CompanyDest, ChangeCompanyT);
IF NOT OK THEN
ERROR(Text001);
.
.
SalesLine.INSERT();

CU50001 (ChangeCompany)

//PART1 - HEADER

SalesHeader.RESET;
SalesHeader.SETRANGE("No.",Rec.SalesNo);
IF SalesHeader.FINDFIRST THEN BEGIN
SalesHeader.VALIDATE("Sell-to Customer No.",Rec.CustomerNo);
SalesHeader.MODIFY;
END;

//PART2 - LINES

SalesLineOri.CHANGECOMPANY(Rec.CompanyName);
SalesLineOri.SETRANGE("Document No.",Rec.SalesOrderNo);
SalesLineOri.SETRANGE("Document Type",Rec.SalesOrderDT);

IF SalesLineOri.FINDFIRST THEN
REPEAT
SalesLine.SETRANGE("Document No.",Rec.SalesNo);
SalesLine.SETRANGE("Document Type",Rec.SalesOrderDT);
IF SalesLine.FINDFIRST THEN
REPEAT
SalesLine.COPY(SalesLineOri);
SalesLine.MODIFY;
UNTIL SalesLine.NEXT = 0;
UNTIL SalesLineOri.NEXT = 0;




My problem is: PART1 does not work with this code, but if I delete PART 2, PART1 works, I do not understand why this happens.

My second problem is: If i delete part 2 and I put the code in CU5000, when i do SalesHeader.VALIDATE some lines of SalesLine are modified. It seems that STARTSESSION does not run sequentially because i modified SalesLine after STARTSESSION in CU5000. I do not understand the operation of STARTSESSION very well.

I'm sorry because maybe my explanation is bad and my English is worse. Thank you very much if someone can help me.

Best Answer

  • juanbo82juanbo82 Member Posts: 8
    Answer ✓
    Finally I solve the change of company with web services.

Answers

  • juanbo82juanbo82 Member Posts: 8
    Answer ✓
    Finally I solve the change of company with web services.
Sign In or Register to comment.