# condition for GL entry document no=salesInvoiceLine Doucment No

**URL:** <https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867>\
**Category:** Developers Forum\
**Created:** [November 10, 2011, 9:31am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867 "2011-11-10T09:31:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![monir\_asian](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@monir\_asian](https://www.dynamicsuser.net/u/monir_asian)\
**Post date:** [November 10, 2011, 9:31am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/1 "2011-11-10T09:31:44Z")

</div>

hello, i want to compare G/L entry document no=sales Invoice Line document no and then calculation line discount.

With G/L entry DO BEGIN

WITH SALES INovice lIne Do begin

Repeat

Repeat

if G/L Entry.DocumentNO=Sales Invoice Line.Document NO then begin

TOTAL:=TOTAL+sales InvoicelIne.LineDiscount%;

END;

UNTIL SALES INVOICE lINE.NEXT=0;

UNTIL G/L entry .next=0;

but it is not working.

how can i do this?

please help me to write this loop.

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [November 10, 2011, 9:40am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/2 "2011-11-10T09:40:07Z")

</div>

You want to do this process for all g/lentries and sales invoice lines?

you need to get the records first and then do repeat like

IF glentry.findset then

repeat

// apply filter on sales invoice line if you want to apply any filters

IF salesinvline.findset then

repeat

// your cal

until salesinvline.next = 0;

until glentry.next = 0;

---

<div class="post-metadata">

**Author:** ![monir\_asian](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@monir\_asian](https://www.dynamicsuser.net/u/monir_asian)\
**Post date:** [November 10, 2011, 9:50am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/3 "2011-11-10T09:50:43Z")

</div>

WITH “G/L Entry” DO BEGIN

WITH “Sales Invoice Line” DO BEGIN

IF “G/L Entry”.FIND(’-’) THEN BEGIN  
REPEAT

REPEAT

IF “G/L Entry”.Amount\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

totalcash\_posted:= totalcash\_posted+“G/L Entry”.Amount;

END;

‘CREDCARD’:  
BEGIN

totalcredit\_posted:= totalcredit\_posted+“G/L Entry”.Amount;

END;  
ELSE BEGIN

totalother\_posted:= totalother\_posted+“G/L Entry”.Amount;

END;

END;  
END;

UNTIL “Sales Invoice Line”.NEXT\<=0;

UNTIL “G/L Entry”.NEXT\<=0;

but when i check glentry.document no=slaes invoice line.documetn no. it is not working?

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [November 10, 2011, 9:57am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/4 "2011-11-10T09:57:04Z")

</div>

I dont think it will work also

WITH “G/L Entry” DO BEGIN

WITH “Sales Invoice Line” DO BEGIN

IF “G/L Entry”.FIND(’-’) THEN BEGIN  
REPEAT

REPEAT

…

try with

WITH “G/L Entry” DO BEGIN

IF “G/L Entry”.FIND(’-’) THEN BEGIN  
REPEAT

WITH “Sales Invoice Line” DO BEGIN

REPEAT

---

<div class="post-metadata">

**Author:** ![monir\_asian](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@monir\_asian](https://www.dynamicsuser.net/u/monir_asian)\
**Post date:** [November 10, 2011, 10:07am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/5 "2011-11-10T10:07:40Z")

</div>

WITH “G/L Entry” DO BEGIN

IF “G/L Entry”.FIND(’-’) THEN BEGIN  
REPEAT

WITH “Sales Invoice Line” DO BEGIN

REPEAT

IF “G/L Entry”.Amount\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

totalcash\_posted:= totalcash\_posted+“G/L Entry”.Amount;

END;

‘CREDCARD’:  
BEGIN

totalcredit\_posted:= totalcredit\_posted+“G/L Entry”.Amount;

END;  
ELSE BEGIN

totalother\_posted:= totalother\_posted+“G/L Entry”.Amount;

END;

END;  
END;

IF GLine.“Inv. Discount (LCY)”\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

BycashtotalInvdiscountGline:= BycashtotalInvdiscountGline+GLine.“Inv. Discount (LCY)”;

END;

‘CREDCARD’:  
BEGIN

BycredittotalInvdiscountGline:= BycredittotalInvdiscountGline+GLine.“Inv. Discount (LCY)”;

END;  
ELSE BEGIN

ByothertotalInvdiscountGline:= ByothertotalInvdiscountGline+GLine.“Inv. Discount (LCY)”;

END;

END;  
END;

IF GLine.“Payment Discount %”\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

BycashtotalPaydiscountGline:= BycashtotalPaydiscountGline+GLine.“Payment Discount %”;

END;

‘CREDCARD’:  
BEGIN

BycredittotalPaydiscountGline:= BycredittotalPaydiscountGline+GLine.“Payment Discount %”;

END;  
ELSE BEGIN

ByothertotalPaydiscountGline:= ByothertotalPaydiscountGline+GLine.“Payment Discount %”;

END;

END;  
END;

IF GLine.“VAT Base Discount %”\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

BycashtotalVatdiscountGline:= BycashtotalVatdiscountGline+GLine.“VAT Base Discount %”;

END;

‘CREDCARD’:  
BEGIN

BycredittotalVatdiscountGline:= BycredittotalVatdiscountGline+GLine.“VAT Base Discount %”;

END;  
ELSE BEGIN

ByothertotalVatdiscountGline:= ByothertotalVatdiscountGline+GLine.“VAT Base Discount %”;

END;

END;  
END;

IF GLine.“Job Line Discount %”\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

BycashtotalPaydiscountGline:= BycashtotalPaydiscountGline+GLine.“Job Line Discount %”;

END;

‘CREDCARD’:  
BEGIN

BycredittotalPaydiscountGline:= BycredittotalPaydiscountGline+GLine.“Job Line Discount %”;

END;  
ELSE BEGIN

ByothertotalPaydiscountGline:= ByothertotalPaydiscountGline+GLine.“Job Line Discount %”;

END;

END;  
END;

IF “Sales Invoice Line”.“Line Discount %”\>0 THEN BEGIN  
CASE “Payment Method Code” OF  
‘CASH’:  
BEGIN

BycashtotalLinediscountSIn:= BycashtotalLinediscountSIn+“Sales Invoice Line”.“Line Discount %”;

END;

‘CREDCARD’:  
BEGIN

BycredittotalLinediscountSIn:= BycredittotalLinediscountSIn+“Sales Invoice Line”.“Line Discount %”;

END;  
ELSE BEGIN

ByothertotalLinediscountSIn:=ByothertotalLinediscountSIn+“Sales Invoice Line”.“Line Discount %”;

END;

END;

END;

UNTIL “Sales Invoice Line”.NEXT\<=0;

END;  
UNTIL “G/L Entry”.NEXT\<=0;

END;

END;

where should i check glentry.documentno=sales invoice line document no?

---

<div class="post-metadata">

**Author:** ![monir\_asian](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@monir\_asian](https://www.dynamicsuser.net/u/monir_asian)\
**Post date:** [November 10, 2011, 10:09am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/6 "2011-11-10T10:09:30Z")

</div>

i want to do this with a function. how can i make a function for it?

---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [November 10, 2011, 10:40am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/7 "2011-11-10T10:40:40Z")

</div>



---

<div class="post-metadata">

**Author:** ![mohana\_cse06](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@mohana\_cse06](https://www.dynamicsuser.net/u/mohana_cse06)\
**Post date:** [November 10, 2011, 10:41am UTC](https://www.dynamicsuser.net/t/condition-for-gl-entry-document-no-salesinvoiceline-doucment-no/33867/8 "2011-11-10T10:41:27Z")

</div>

As I said in my first post

you should add

IF glentry.findset then

repeat

**// Here you need to put setrange on Document No.**

IF salesinvline.findset then

repeat

// your cal

until salesinvline.next = 0;

until glentry.next = 0;
