Setting Default AR Invoice Dates
Users sometimes forget to assign a Bill Date and Due Date to an AR invoice when they create it in ARBTARUB. When this occurs, a default value is saved based upon the Reference (Invoice) Date. The Bill Date field is set to the value of the Reference Date field and the Due Date field is set to the value of the Reference Date field plus thirty days. The Reference Date field is stored in the ARBirMaster table and the Bill Date and Due Date fields are stored in the ARBatchDetail table. Because they are in separate tables, when they user attempts to set them in a PREACCEPT subroutine, it will not update them based on the value of the Reference Date field because that field has also not yet been saved to the current record.
To resolve this problem, the user may populate the fields after the record has been saved by creating a default rule in a POSTINSERT subroutine in the ARBatchDetail script as described below.
Default Rules
In the NU Default Rules (NUUPDF) function, load the script for the ARBatchDetail entity by clicking its name in the Entity List pane.
XML
Click the XML tab in the center section of the window. The following information describes the steps necessary for adding the code that allows a new subroutine to be created and instructing the system when to run it.
Look for a section of text that begins with a text element that says <POSTINSERT> and ends with a text element that says </POSTINSERT>.
If one does not already exist, add one as follows: Place your cursor after one of the ending tags for an existing section. These can be identified because they will be in a format like </PREACCEPT>, </INITNEW>, or </CHANGEREF>. It is important to note that these end tags all begin with "</" which differentiates them from the corresponding beginning tags that do not have the "/." Be certain to click after the ending tag and press Enter to insert a new line.
On the new line, enter a beginning tag for the section by typing <POSTINSERT> and press Enter. Press Enter again to insert another blank line and type the ending tag on the new line: </POSTINSERT>. There should be a blank line between the <POSTINSERT> tag and the </POSTINSERT> tag. (If there isn't, place your cursor after the <POSTINSERT> tag and press Enter to add a new line between the other two.)
On the blank line between the two tags enter:
<RULEOBJECT SCRIPTLOCATION="Defaults" SCRIPTNAME="ARBatchDetail">
Press Enter twice to insert two new lines. Note that the added text will not be line-wrapped. It will all be entered on a single line. Add an ending tag on the second blank space by typing:
</RULEOBJECT>
Once again, there should be a blank line between the two tags for the name the subroutine you will be creating to set the field values. If the <POSTINSERT> section already existed, and you did not need to create it as shown in step above, you will need to enter a new line in the existing section. Do this by placing your cursor at the end of an existing line and pressing the Enter key on your keyboard. A good place to do this is generally at the end of the line above the </RULEOBJECT> tag. On the blank line created in step above, enter information about the subroutine. To do this we will enter the following line of text:
<METHOD ID="ARBatchDetail_AR_PostInsert" />
Once again, this should be entered as a single line of text.
Script
Now, you may add the script that tells the system what you want it to do. To do this, first highlight the section of text in the XML code we just added that says ARBatchDetail_AR_PostInsert and copy it to the Windows clipboard by either right-clicking or selecting Copy from the popup window or by using a Ctrl-C shortcut key combination. After the text has been copied to the clipboard, click the Script tab in the center section of the page. This is where you will actually enter the subroutine information that tells the system what to do.
Place your cursor on a blank line after a line that says, "End Sub" and press Enter to add new line. On the new line, enter the word Sub followed by a space and then paste the text we copied from the XML code into the line following the space. You can do this by right-clicking the line and selecting Paste from the pop-up window or using the Ctrl-v keyboard shortcut combination. After the pasted text you will need to type in a left and right parentheses symbol so the line will read as follows:
Sub ARBatchDetail_AR_PostInsert ()
Press the Enter key twice to add two new lines. Sub is a keyword that indicates the start of a subroutine. It must be matched with a line that indicates when the subroutine definition is finished. On the second blank line, add the following text to indicate the subroutine is completed:
End Sub
On the empty line above the End Sub line, add the body of the subroutine. Place your cursor on this line and press the space bar twice to add two blank spaces before you begin typing the text. This is done for easier readability. After the two blank spaces, enter the following line of text press Enter to add a new line:
If not (CurrentPageMask = "ARBTARUB") Then
"If" is a keyword that identifies a comparison that will be made and what actions will be taken. It is accompanied by the keyword "Then" and must also have an accompanying keyword of "End If." The text between the "If" and "Then" identify what is being compared which in this case it is checking to see if the ARBTARUB page is being used to set these defaults. If it is not (which makes the statement "True") then the actions identified between the keyword "Then" and the "End If" keyword will be performed. If it is the ARBTARUB page, then the rest of the statement is ignored and the program reads the next line of code after the "End If" keyword. On the new line, press the space bar five times to enter blank spaces (to promote better readability) and enter the following line of text before pressing the Enter key again:
Exit Sub
This line is executed if the page being loaded is not the ARBTARUB page. It tells the system to exit the subroutine without performing any additional actions. On the new blank line, press the backspace key until the cursor is below the "I" in the line that began with "If not" and add the following line of text before pressing the Enter key on your keyboard twice:
End If
This line indicates that the "If…Then" statement is now complete. On the new blank line, add the following text before pressing the Enter key twice:
Call ifas.ResetValueList()
This line tells the system to call one of its standard procedures used to reset values. "Call" is a keyword that tells the system it needs to do something. On a new blank line, enter the following line of text before pressing Enter once:
'Global settings for all users, all ledgers
The ' symbol at the start of the line indicates that the rest of the text following it is a comment used to provide information to the user reading the script. Comments are ignored by the program but frequently used by programmers to provide information about what a section of code is supposed to be doing. In this case, it indicates that the lines of text following it are default settings and that they apply to all users and all ledgers. On the new blank line, add the following text before pressing Enter:
Call ifas.SetValueOnce ("BillDt",IFAS.CurrentRecord.RefDt)
This is the first line of code that is actually used to set a default value. The keyword "Call" instructs the system to initiate the standard BusinessPlus function ifas.SetValueOnce. The information inside the parentheses is passed to the function. The first piece is the field that the default is to be set for, which in this case is the BillDt field. The second piece after the comma is the value the BillDt field is to be set to. In this case, the field is being set to the value of the RefDt field in the current record. On the next new blank line, type the following line of text before pressing Enter:
Call ifas.SetValueOnce ("DueDt",IFAS.CurrentRecord.RefDt + 30)
This is the second line of code that is used to set a default value. It works in the same manner as the previous line entered in above. The first piece inside the parentheses is the field that the default is to be set for, which in this case is the DueDt field. The second piece after the comma is the value the DueDt field is to be set to. In this case, the field is being set to the value of the RefDt field in the current record + 30 days. After entering the subroutine text, click the Save icon in the toolbar above the Entity List. If ARBTARUB page is already open, it must be closed and reopened (or refreshed) in order for the changes to appear.