--- title: "How Do I Eliminate Unwanted Whitespace When a Script is Run as First Pass?" slug: "eliminate-unwanted-white-space-with-run-script-at-first-pass" description: "You can eliminate unwanted white space from your forms with “Run Script at First Pass”. The following article will show you how to do this." updated: 2024-06-17T11:02:15Z published: 2024-06-17T11:02:15Z canonical: "kb.lasernetgroup.com/eliminate-unwanted-white-space-with-run-script-at-first-pass" --- > ## Documentation Index > Fetch the complete documentation index at: https://kb.lasernetgroup.com/llms.txt > Use this file to discover all available pages before exploring further. # How Do I Eliminate Unwanted White Space When a Script is Run as First Pass? You can eliminate unwanted white space from your forms with **Run Script at First Pass**. The following article will explain how. This article assumes you are familiar with conditional rearranges, database commands and scripting with Lasernet. It will not go into detail about setting those up. We will be augmenting an example form with some additional data from another database table so our customers have more information about each example part we stock. Currently, our report (shown below) only has a single line of information against each part number: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-DTYS6RWA.png) Whereas our database table has a number of additional lines of useful information for each part number that we would like to include: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-E3FKRLE3.png) To solve this problem, we could have the standard report altered in the ERP system to include all the information and then map it to the form. However, these alterations (regardless of size) will have to be done every time the ERP system is upgraded and will likely incur additional consultancy costs from your ERP provider. Alternatively, this information can be quickly and easily extracted by Lasernet and placed on the form by using a script to call the database. ## Create your Script The following information can be used as a guide in creating your script. In this example, the script is called on a rearrange that maps the part number to the page. The part numbers in our data match the **Type** field in our database, and that is the value that will be passed into the database call We do not want the part number to show in the form, so the function is only being used to run the database command. For example, the part number is not returned to the page out of the function The **JobInfo** array that will be created from the database call will be called **Text**, as that is the name of the field in the database we are extracting: ```plaintext function testFirstPass() { job.deleteJobInfo("Text");    //Delete previous jobinfo array called Text so it is clean         job.setJobInfo("passval", Trim(CurrentText)); //Set Jobinfo passval to the value that we are currently mapping (current part number) - See Notes for more info. databasecommands["Test sql"].run(job);  //Run the database command called "Test sql"             return ""; //return blank to the page } ``` Where the **Database Command** (**Test sql**) being called is: ```plaintext SELECT Text FROM Test WHERE type = '#passval#' ``` If there is more than one entry in the database for a particular part number, you will get back a **JobInfo** array of values T**ext[0]**,**Text[1]**,**Text[2}**…**Text[n]** Follow these steps: 1. Use the following image as a guide to adding the database call script to your form: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-K5K66YV6.png) 1. Once you have applied the javascript call to the part number, use the **Add** button on the same rearrange to add the function **getDesc()**, which will fetch the values from the **JobInfo** array (**Text**) and add them to the final string. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-BZTH662I.png) ```plaintext function getDesc(x) { //Index x is passed into this function and it returns the value at index x in the job info array return job.getJobInfo("Text",x); } ``` In our example table, you can see that there is a maximum of five possible extra lines of description that can come back from the database call. As such, there would need to be five calls to the **getDesc() f**unction, each one passing in its own index (0-4). For each extra description line to be added to a new line, ensure the new line after the checkbox is selected on each function call. 1. Ensure that the progress on the conditional pattern that maps the part number is large enough to cater to the maximum amount of extra description lines that can exist. In this case, **35mm** would be sufficient enough spacing to ensure the next item does not overwrite the current item. In general terms, the progress value will usually depend on the maximum amount of extra lines that can be returned from your database. Setting the value to **35mm** at this stage is done purely to illustrate how extra whitespace can appear in a form. Normally, you would reduce this to a sensible value when the gapping becomes dynamic between each item. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-GI4TUHNH.png) When you run the script in the form (**shift+F5**), the following is displayed: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-QQW0PNI9.png) 1. As expected, large gaps of white space are now present between items that only have one or two extra lines of description associated with them. 2. Change the progress value on the pattern from **35mm** to **10mm** and tick the **progress is relative to highest re-arrange** box. If you run the script now (**shift+F5**), you can see that we still do not get the result that we want. We get the same result with **10mm** extra space added than before. Leave the value set to 10mm for now. 6. Select the **Run Script at First Pass** checkbox for each function call on both **TestFirstPass()** and each **getDesc() i**n the rearrange. At this stage, Lasernet is calculating the spacing, but it does not yet know how many lines of data will be returned by the database call. For this reason, the **Run Script at First Pass** checkbox was implemented. Its purpose is to run the database call and find out exactly how many lines will be returned to the re-arrange from the database before any other space processing is calculated. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-P5FFFL0K.png) 1. The **Progress is relative to the highest Rearrange** will now work correctly because it knows the number of lines that are going to be returned into that space. 2. Set the **Use Empty Line Height** on the rearrange (output tab of the re-arrange). You should select the box and set it to **0mm**, which means if the re-arrange line is blank, then no vertical progress is added, and any empty lines of description are therefore removed. ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-UBZXACH8.png) After completing these steps, the form is now free of unnecessary white space between items: ![](https://cdn.document360.io/c831ef63-c6b3-48ee-b443-3e33644e4e2e/Images/Documentation/image-K6N90BOH.png) Because the script is running at first pass, we can only use the direct object method of collecting the part number **Trim(CurrentText)**, because at First Pass Lasernet has no knowledge of the re-arrange name. Likewise, this would not work if we tried collecting the part number via a **JobInfo**, as again, at first pass phase, Lasernet does not know anything about the values of **JobInfos** yet. ```plaintext job.setJobInfo("passval", Trim(CurrentText)); ```