# Problem with code in onQueryClosePage trigger

**URL:** <https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676>\
**Category:** Developers Forum\
**Created:** [October 8, 2013, 2:27pm UTC](https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676 "2013-10-08T14:27:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![poppins](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@poppins](https://www.dynamicsuser.net/u/poppins)\
**Post date:** [October 8, 2013, 2:27pm UTC](https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676/1 "2013-10-08T14:27:35Z")

</div>

Hi everyone,

I have added some code (the lines I added are in bold)in the onQueryClosePage trigger in page 5708 (Get Shipment Lines).

`IF CloseAction IN [ACTION::OK,ACTION::LookupOK] THEN`  
` **salesshipline.RESET;** `  
`**CurrPage.SETSELECTIONFILTER(salesshipline);**`  
` **IF salesshipline.FINDFIRST THEN** `  
` **REPEAT** `  
` **IF salesshipline."Num Facture en cours"<>'' THEN** `  
`**ERROR('Ce BL est déja généré dans la Facture %1',salesshipline."Num Facture en cours");**`  
` **UNTIL salesshipline.NEXT=0;** `  
`CreateLines;`

When I press escape to quit the page, the error message is displayed again and I am stuck in the page ![:mrgreen:](http://www.mibuso.com/forum/images/smilies/icon_mrgreen.gif)

What shall I do to be able to quit the page when I press escape???

![](http://www.mibuso.com/forum/images/spacer.gif)

---

<div class="post-metadata">

**Author:** ![poppins](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@poppins](https://www.dynamicsuser.net/u/poppins)\
**Post date:** [October 8, 2013, 2:28pm UTC](https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676/2 "2013-10-08T14:28:48Z")

</div>

By the way, the version of NAV I am using is 2013.

---

<div class="post-metadata">

**Author:** ![George\_Love](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@George\_Love](https://www.dynamicsuser.net/u/George_Love)\
**Post date:** [October 8, 2013, 4:20pm UTC](https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676/3 "2013-10-08T16:20:20Z")

</div>

This might post twice, but … change IF … THEN statement to IF … THEN BEGIN/END;

---

<div class="post-metadata">

**Author:** ![George\_Love](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@George\_Love](https://www.dynamicsuser.net/u/George_Love)\
**Post date:** [October 8, 2013, 6:43pm UTC](https://www.dynamicsuser.net/t/problem-with-code-in-onqueryclosepage-trigger/48676/4 "2013-10-08T18:43:14Z")

</div>

To clarify … the original statement was

IF CloseAction IN [ACTION::OK,ACTION::LookupOK] THEN

CreateLines;

Now, you’ve added several lines between the original condition statement and the CreateLines statement. But, since the original condition statement was in the form of IF…THEN, and you haven’t modified it, the condition, if true, will still only run the first command following the condition. If you want the entire block to run conditionally, then you’ll need to wrap all of the commands in a BEGIN/END block.

Hope that makes more sense.
