Scripting

Published: March 22, 2016

Description:

Transcript

Introduction

Welcome to this training video / webinar on designing, implementing, and testing a visual basic script in the Nortridge Loan System.

For the purpose of this exercise, we will begin with a process that we want to automate, and then I will take you through all of the steps that we need in NLS to configure the system for that process, design and program a script to automate that process, debug it as we go, and test it.

We have decided for the premise for this script, we will assume that the lender charges a fee when a borrower requests that a new copy of their statement be printed and mailed. We are going to automate the application of this fee.

Let's go over some of the assumptions that will represent the business rules involved. Our fee will generally be $10, but let us assume that we lend in several states that have a statutory maximum requiring that the fee be no more than $5. While we could design our script to check the contact associated with the loan, check the address on that contact for the state, and then based on a list coded within the script determine the amount of the fee, to maintain flexibility, simplify the programming, and show how the user defined field setup relates to the scripting, we will configure a user defined drop list with the options $5 and $10. As a failsafe, we will also configure $0 into that field and this will be the default value.

To execute the fee, the user will need to select $5 or $10 and then click a button. This will initiate the execution of the visual basic script.

The script will run a custom receivable transaction code for the amount that was specified in the drop list, set the list back to the default value of $0, pop up a message box indicating that the fee was successfully added to the loan, and then refresh the values on the screen.

It is our hope that the procedures for this script would be adaptable for any automation of a custom transaction code, and therefore will be useful to any users wanting to write and configure a similar script. Additionally, it should provide some insight into the design process.

Lastly, let me mention that I am not a programmer, and as such I will be doing some of these things in ways that might not be the most efficient or elegant. This is deliberate. I am going to write the script in a way that I can understand, as I have learned to do through several years of trial and error, and if the methods and procedures that I use and the way that I use them are understandable to me, a non-programmer, then they should be understandable to you too. As such, I have deliberately included in my outline for this video/webinar the mistakes that I initially made in the process of designing and implementing this script so that you can see the trial and error process of the scripting procedure.

So, on to the first step: Transaction code and user defined field configuration. But before that, we do need a database in which to develop and test our code.

Development Database

If you are going to do scripting, you need to have a database in which you can do your development, test your configurations and scripts, and not impact your production data. For the purposes of this demonstration, I have created a new, blank NLS database with the default starting configuration. You should use a copy of your production data, so that you will be working with your actual custom transaction code setup and user defined field configuration. How you go about creating or acquiring this database will differ depending upon if you are using a hosted or non-hosted version of NLS

Hosted

If you run the loan system in a hosted environment, you will want to contact your sales rep and ask for a test copy of your database that you can use for testing and script development purposes. This will involve a small increase to your monthly fees, but should be well worthwhile. A new database instance will be created for you, and a backup copy of your database configuration will be restored into that instance. Then, when you log into the remote desktop, your NLS log in will have a drop list indicating which database you wish to do into. For proper testing and development, it is useful that this database be initialized as a copy of your production data, but that does bring up one point about which you need to be careful: the screen configurations and data inside the two databases will look the same. You therefore need to be careful when logging on. If you were not careful, you would not be the first person to find that the entire batch of payments that you entered yesterday are missing and after some panic realize it is because you entered the whole batch into your development database, where those same loans did exist. Don't let that happen to you.

Non-Hosted

If your NLS environment is not hosted, then you have either Oracle or Microsoft SQL server on site. Make a new database, using a name like NLSDevelopment. Then do a restore into that database of the latest backup from your production database. Your database administrator should know how to do this. Lastly, configure a second connection on the connections page of your NLS log in screen so that it points to the NLSDevelopment database. Since you have used a copy of your production database, the warning about making sure you are in the write database for what you are doing still holds, but in this case, you need only configure the connection to the development database on the NLS instance at the developer's work station. The data entry people and production CSRs need not have access to that database configured at all, so in this case it is a bit easier to manage the connection and make sure it is always to the proper database for the person doing the job.

Configuration of Custom Transaction Code

Log on to database aa_scriptwebinar.

I am logging into the database that I have prepared for developing this script. Before we start on the script, we will need to configure the user defined fields that will be executing the script, and also the custom transaction code that the script will be executing.

I'll do the custom transaction code first.

navigate: Setup->Loan Setup->Transaction Codes

Here I will activate the wizard for adding a custom transaction code. In this case, because it will be a receivable transaction, we have to actually set up two trans codes, the receivable and its payment.

add button

All transaction code numbers above 500 (inclusive of 500) are reserved for custom codes. Reversals are the odd numbered codes one higher than the transaction that they reverse, so I will use 500 for my receivable and 502 for the payment.

Transaction Code: 500

Name of Transaction: Statement Fee

Copy and paste into next two fields.

Leave transaction type to receivable.

Next

Since this transaction code is a receivable, I get an extra window in the wizard. I have to specify which loan balance the statement fee sits in between the time it is assessed and the time it is paid. We can stick it in "fees." That is where NSF charges go. Or we can use a user defined loan balance so that it remains separate from the NSFs and other kinds of fees that are pre-configured. I will choose to do that.

Select User Def #1 from the drop list.

Once we have completed the configuration of the transaction code, we will go and change the name of this loan balance from User Def 1 to Statement Fee.

Now, I have to tell the wizard what transaction code number to use for the payment.

Enter 502.

Next

On the next page of the wizard, we must define the general ledger controls for the transaction. I will go ahead and make this transaction behave on accrual basis, debiting accrued fees and crediting fees income when it is assessed.

Debit1: PH Accrued Fees 1

Credit1: PH Fees Income 1

Next

Primary Classification is used for grouping the transactions on various reports. We will designate this one as a Fee.

Primary Classification: Fee

Now, the Loan Balance affected Must Be the same as the loan balance that we specified for the receivable. That does, however, beg the question of why do we require you to specify the same thing twice. If they were always the same then shouldn't the wizard just set them the same and be done with it? Because setting a different loan balance here from in the other place causes major problems when we try to make a payment. Well, the answer is that there is a certain kind of configuration where the two would be different, and an example of that would be a case where one, non-receivable transaction code increased the loan balance, and then at a later time we used a receivable transaction code to bill that existing loan balance. In that case, we need that first one to tell us which balance we are billing, but when we create that billing we would NOT be increasing the loan balance in question at that time as it had already been established. It is similar to how interest is billed once a month when it previously accrued over the course of the month on a daily basis. The interest balance does not go up at the point in time at which we bill it.

Loan Balance Affected: UDF 1

But in this case we are increasing the balance at this moment: we are assessing and billing the fee at the same time. And it is an increase to the fee balance.

But in this case we are incSet to Increase

Next

We could track statistics on this fee, but we don't have to.

Next

There is no voucher processing involved

Next

And no special options need to be checked.

Finish

As you can see, NLS pops up a reminder that since we are entering a receivable, we must also configure the associated payment.

OK

Name of Transaction: Statement Fee Payment

Copy and Paste into next two fields.

Next

The general ledger for the actual payment would be a debit to cash and a credit to the accrued fees.

Debit 1: PH Cash Account 1

Credit 1: PH Accrued Fees 1

Next

The primary classification of this one is a Payment

Primary Classification: Payment

The same loan balance is affected, but the payment decreases it.

Loan Balance affected: UDB1 - Decrease

Next

Next

Next

Finish.

Now, let's go to labels

Click Labels under Loan Setup

And we are going to set the name for the first user defined loan balance to Statement Fee

Loan Balance - User Defined #1 - Statement Fee

And we are going to save all of our changes.

OK

and we are going to reboot NLS to confirm these changes.

Yes

Log back in.

Configuration of User Defined Fields

Next, we are going to configure two user defined fields on the loan screen. In order to do that, we must first have a loan, and we can't have a loan without a contact, so I will quickly create a dummy contact and dummy loan so that we have something to work with.

Go to contact. Add contact with name TEST.

Add test loan; parameters are irrelevant. Exit contact and query the loan.

Now we are going to go to the detail tab where we will configure our user defined fields.

Go to Detail 1

I'm going to make the first field into a drop list.

Right click the field and select setup.

Field Label: Statement Fee Amount

Field Type: Drop List (Select Only)

Now, I am going to enter my selections in the field, which will be zero, five, and ten.

Add selections: 0.00, 5.00, and 10.00.

And I click OK to save the setup of this user defined field.

OK

Next, I will make the second user defined field into a button.

A button can be set up to activate multiple scripts. So we click the add button here to enter the names of the various scripts that could be activated from the button. If we set only one, as we are going to do, then that name will become the label for the button. If we set more than one, then the button would become a drop list to select one before clicking the button.

Right click on second field and select setup.

Make mixed case

Add script name: Assess Statement Fee

OK

Next, I'm just going to put a place holder for script activation.

msgbox ("Assessing Statement Fee")

OK

So, when we click the box, we will see that the script is activating, because the message box comes up.

Click button to activate script.

Now, we just have to replace that one line of script code with the actual script that we want to activate, which we now need to design, code, debug, and test.

Script Design

So, we are ready to begin scripting. I will first begin with some comments at the top of the script so that anyone looking at the script later will know what it is supposed to do, who wrote it, when, and how it is activated. For comments in vb script the line is simply begun with an apostrophe. This indicates to the vb script compiler that this line of code is simply to be ignored. it is for us carbon based computers to be able to look at but not for the silicon. So, it will go like this:

                
              'Assess Statement Fee
              'By Aaron Abrams
              'Today's date
              'Activate on button click
                
              

Once my script activation starts returning any output during testing, I will take out the message box.

Next, I am going to decide what the broad strokes of what will be done shall be, and I will use comment lines to define those within the script. Then we will go back and flesh each of those out with actual code that does something.

So, what are the things that are going to happen when we click the button.

First, I am going to assume, that the user might not have click the save button after setting the statement fee amount field, and therefore, my record might be locked, so I am going to have the script throw a save screen.

Next, I am going to grab the value in that field.

Once I have the value in that field, I am going to set the value in the field back to zero.

Then, I will assess the statement fee for the amount of the value that I have grabbed.

Once the fee has been assessed, I am going to save and refresh the record again.

And lastly, I will flash a message box showing what was done.

I am going to add these items as comment, with space between where we will put our programming code.

                
                  msgbox ("Assessing Statement Fee")
                  'Assess Statement Fee
                  'By Aaron Abrams
                  'Today's date
                  'Activate on button click
                  'Save and Refresh
                  'Get Fee amount
                  'Zero Fee amount field
                  'Assess Statement Fee
                  'Save and Refresh
                  'Results Message
                 
               

Save and Refresh

Now, when it comes to using any functions in our COM interface, which is how NLS interfaces with VB script, I am not going to assume that we know how to do anything. I'm going to show you how we look everything up. So, we will start by opening the COM.API document that will be used for showing us how to do everything that we need to do. This is one of two references that we will have to use. Eventually, when it becomes time to assess the actual transaction, we will have to use the import interface for that.

So, I start by opening the API document.

Open API doc.

This is the COM Programatic Interface Reference. For our initial save and Refresh, we will find the function we need on pages 64 and 63.

Go to page 64.

We are interested in the save screen function. The word void simply tells us that the function does not return any variables. The fact that there is nothing inside the parenthesis tells us that we do not have to pass any variables. I do need to tell the code that this function is being called from the NLS Application, so I will precede the function with "nlsapp" followed by a period before the function.

After we do a save, which will unlock the record, we will do a refresh. That way, the screen we are looking at will always reflect the current data. It may not be necessary at this time, but I always do these two together.

Go to page 63

So, I am going to go ahead and add these two lines of code.

msgbox ("Assessing Statement Fee")

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

                
                  nlsapp.savescreen()
                  nlsapp.refreshscreen()
                
              

'Get Fee amount

'Zero Fee amount field

'Assess Statement Fee

'Save and Refresh

'Results Message

Testing

Now, we test. If I set a value in our Statement fee amount drop list, you will see that the save button becomes active, indicating a "dirty" record, which would lock the fields if we were to try to do a query on them. Clicking our button now should save the record, unlocking it so that the rest of the script can work appropriately.

Select $5 from Statement Fee Amount.

Click button

See that we got our message box, and then the save button went grey, indicating that there is no longer anything to save. That is because it did save the value. Since we now have the script actually doing something, we can go ahead and take our placeholder out.

Remove:

msgbox ("Assessing Statement Fee")

Get Fee Amount

Now that we have an amount in the fee amount field, we are going to go and grab that value and store it in a variable. For debugging purposes, we will display the variable in a message box, and then when we move on to later parts of the script where we use the variable, we will use the apostrophe to "Comment Out" that message box.

For setting the variable, we are going to use a command called "Get Field." We can find that on page 54.

Go to page 54 of the COM API Doc.

The argument inside the parenthesis is the field name. The contents of the field will be returned and assigned as a string value to the variable that we are setting. For the list of field names and how those are formatted, we will go to page 68.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

                
                  FeeAmount = nlsapp.getfield("cif_detail_udf1")
                  msgbox(FeeAmount)
                
              

'Zero Fee amount field

'Assess Statement Fee

'Save and Refresh

'Results Message

Now, the message box is going to tell me if I programmed this correctly, and also how it is formatted; two separate but important pieces of information that we will separately use.

Click the button.

The message box returned a blank. As my friends from "Across the Pond" would say, "I bollixed something." And I see what it is. We are not on the contact, also known as the CIF. We are on the loan screen. The field that I want is on page 70.

Go to page 70 of the API doc.

There it is. Let me fix that.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

'Assess Statement Fee

'Save and Refresh

'Results Message

Click button to test.

Ah, that's better. Now, the fact that it came out as 5.00 is telling me that it is coming over as a string, which is what we expected based on the information we saw on the function call in the API doc. We may need to convert it into a numeric datatype later, but depending on what we do with it and how we are going to use it, we may have to keep it as a string, so I will just leave it alone for now.

Zero Fee Amount Field

Now that we have the value from the drop list in memory, set in a variable that we are going to use later, we will set the drop list back to zero.

We will use the set field function, which we will find on page 64

Go to page 64.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

'Save and Refresh

'Results Message

And for testing purposes, I will skip ahead and add my save and refresh.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

To test, I will select the ten value and click the button.

Select 10.00 in first field and click button.

As you could see, our message box flashed the value 10.00 and then the drop list reset itself to 0.00.

Now, all the easy stuff is done. Here is where it gets interesting.

Assess Statement Fee

To assess the fee we will use a combination of several functions. First, let's look at the Import XML Record function. This function is detailed on page 58.

Go to page 58.

Looks simple, but here is a case where looks are deceiving. An entire XML file is what we need to pass as our parameter, so how the heck do we do that. How do we build and XML file within a vb script?

To do this, we are going to use a special function called an XML Parser. It basically allows us to manipulate text to build a text file as a variable and then pass that variable (it being the entire text file we just built) as the parameter into our import xml function. The parser function is detailed on page 57.

Go to Page 57.

So, as we see in the example, the parser has three sections. First we will set the parser by calling the parser function. The second line builds the parser, and the third line loads the parser into the function we are calling. But for us, due to the complexity of the XML file that we will need to build to import a payment, the "second line" will be much more than a single line.

So, we will start with the "Set Parser" command.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now we are going to use two vb script commands that are used for setting up an xml file within the script. The two commands are called "intoelem" and "addelem." They are used to insert an element into an xml line and to add an xml line. Many of you certainly know and understand XML better than I do, so if I am not explaining these correctly, please take this in the context of my programming skill and knowledge being just sufficient to be dangerous. I will show you how to use the two commands even though I may not fully understand why they are used in this way.

So, now, we need to reference our XML specification for the formatting of the XML file and then we will use the two commands to achieve this.

Open XML specifications document.

We see here on the first page that the first line of any XML import must be the tag "NLS" inside the brackets or braces of the type that are used in math as the greater than and less than symbol. So to parse this, we will use the into element followed by the add element like this:

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Next, we are going to indent in our XML to do a sub-element of NLS. In the XML example being shown on page 1 of the document, the sub element is CIF, meaning that they are importing a contact. We are going to import a transaction, so we will use the sub-element transactions, and we will find the information for that sub element on page 59 of the XML document

Go to page 59.

We can see here that Transactions IS a sub-element of NLS, so we are in the right place in the XML tree hierarchy.

We will use into element and add element to add this level of the hierarchy to the XML file.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

                  
                     parser.intoelem
                     parser.addelem "TRANSACTIONS", ""
                   
                

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now, looking at the XML document, we need to see if we have to go down another level, and if we have any attributes that MUST be added at this level.

Notice that all of the attributes at this level are optional. None are required attributes.

The sub-element that we want is on page 63.

Go to page 63.

Since we are going to run a custom transaction code, we will use the sub element of transaction code and all of the necessary attributes of that sub-element.

We will start by using into element and add element again to add this sub-element to the XML file. Note that in the document, it does state that this sub element is a sub element of transactions, so we are still in the right place in the hierarchy.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

                  
                    parser.intoelem
                    parser.addelem "TRANSACTIONCODE", ""
                  
                

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now, we will look at the document to see what attributes are required and we are going to use the add attribute command to add them. Many of the required attributes are values that we do not have yet. So, we are going to use some variables that we have not yet defined, and when we test we will get an error message as a result. Then we will go back and define all of the variables that are required.

So, we can see in the document that the first attribute that we have to add is the transaction code number itself. Now we defined the transaction code earlier so we are going to hard code the number. And that number is 500.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

The 500 is in quotes because we are actually sending the value 500. When we use a variable as we will do for most of the attributes that we set, the variable name will NOT be in quotes.

Referring back to the document, we can see that the next required attribute is the effective date for the transaction. We will add the attribute for the effective date, setting it to a variable, and later we will go back and define that variable.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", "">

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

                    
                  parser.addattrib "EffectiveDate", EffectiveDate
                    
                  

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Next we need to pass the loan number. This is so the transaction gets applied to the correct loan. We will use a get field command later to grab that. For now, the line of script will be like this.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

We don't need payment method, payment method reference, or reference fields.

We do need the amount, but we have already defined a variable with that value.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

The remaining fields in the Transaction Code Sub-element are not required fields. However, some may be necessary in the context of what we are trying to accomplish, so let's review which of the remaining fields may be needed.

Point out Due Date Field

This field "Due Date" is required if the transaction code is a receivable. So we do need that one. Now, we have not yet decided what the due date should be or how we will decide that, but that is okay for now. Like some of these other fields, we will parse the due date field into the XML now with a variable that we have not yet defined, and then we will go back and define it later.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

And that is the last value we need to parse into our XML file, so we just have to add a line to tell the script to attempt to import the XML document. We will use a format that will return the error message if there is one.

'Assess Statement Fee

y Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee>

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Testing

Now we are going to go ahead and test the import, knowing full well that it is going to fail and fail hard because we have not yet defined all of the variables that we used in the parsing of the XML import. But, I am quite interested to see what the system tells us in the form of the error messages when it attempts the import, and how helpful those error messages are.

Click button.

Nothing happened. No error message came back. Suddenly, it occurs to me that we just sent the value zero which was set the last time through. We had better select either the 5 or 10 value when we test.

Select $5 then click button.

And again, nothing happened. So actually, what is happening here, let's refer to the code, so that I can explain.

Bring up the script code.

The value being returned by the return value command is True if the XML imported successfully, and false if it did not. We know and expect that it did not, but I did not actually tell it to show me the error message. We are going to do that like this:

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now we will try again and see if we get the error message we are expecting.

Click the button.

I got a message indicating an invalid loan number. Now we are in business. I never defined the loan number variable. I knew that and was expecting it to error for that specific reason. That means this is working the way it is supposed to and we are on the right track. I have never been so happy to see an error message.

Let's define the loan number.

Defining the Loan number variable.

Once again, we will use the getfield command on page 54 of the API doc.

Go to page 54 of the API doc.

And I will refer to page 69 for the list of fields that I can get and how they are formatted.

Go to page 69.

I am going to define the variable in my script, with a message box to see what is being returned. At this time, we can comment out the message box for the amount since that is returning okay, and it will get confusing if we have too many of those message boxes active.

We have to insert the code to define the variable BEFORE we start the parsing, so it will go like this:

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

msgbox(LoanNumber)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now, when I test, I expect a message box with my loan number and then I expect a different error message to return from the XML to tell me something else that we have not yet defined.

Select $5 and Click the button.

Now, it is showing us that our date due is invalid. Interesting that we never got an error about effective date. Perhaps it defaults to today when not defined. If so, that was what we were going to set anyway, but that is a bridge we will cross when we come to it. For now, let's move on to defining the due date for the receivable we are setting.

Defining the Due Date

So, let's decide to set the due date for the fee transaction to be the date of the next billing, so that the fee is due along with the next payment that will be billed. We can use the getfield command to grab that date. Let's look at the field list on page 70.

Go to page 70 in API doc.

We have to choose between next principal due date or next interest due date. For most types of loans these will be the same, so let's consider the exceptions. I am going to assume that interest only loans are more common than principal only loans, and therefore we will use the next interest due date. We will use a message box to look at the formatting of the data that comes back, and then we may have to manipulate it to get it into the right format for our XML.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

msgbox(LoanNumber)

date = nlsapp.getfield("loan_nextintduedate")

msgbox(date)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Now we will set the amount and click the button to see what comes from that date field.

Set $5 and Click button.

Illegal assignment. Okay. Date is a reserved word. Can't use that as our variable. Now, ultimately, we have set the variable that we are going to define to DateDue, but right now I am wanting a different variable before I do the reformatting, if necessary, for the XML. So, okay. We'll use DueDate.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

msgbox(LoanNumber)

duedate = nlsapp.getfield("loan_nextintduedate")

msgbox(duedate)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

We still got an invalid due date error from the XML, but we hadn't changed what we were passing for that field to the XML yet, so that was expected. The important thing to note is that we got the date back, and we got it in the format mm/dd/yyyy. Now, let's take a look at the XML specification and see what format that date is supposed to be in. We will go to page 63.

Go to page 63 of the XML doc.

Looks like get field is returning the date in the format that we actually needed. How convenient. I, however, assumed nothing. I just need to reverse the order of the words due and date in my variable name, and I should be all set on this particular one. At the same time, I will comment out the message box for the loannumber.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

'msgbox(LoanNumber)

DateDue = nlsapp.getfield("loan_nextintduedate")

msgbox(DateDue)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

And we are ready to test again.

Set $5 and click the button.

I'm getting a failure obtaining a record lock. Looking back at what we did, I can see that we inserted the value zero into our drop down, and then did not do a save and refresh before trying to do this import. So, sticking in another save and refresh right after that user defined field modification should fix that problem.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

'msgbox(LoanNumber)

DateDue = nlsapp.getfield("loan_nextintduedate")

msgbox(DateDue)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

Let's try it again.

Set $5 and click the button.

I got no error message. Does that mean that the transaction successfully imported. Let's take a look in a few places.

Go to Payments Due

There it is.

Go to Transaction History

And there it is in the transaction history. So, now, let's just put a message up on the screen to tell the user that it worked, so they don't have to wonder.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

'msgbox(LoanNumber)

DateDue = nlsapp.getfield("loan_nextintduedate")

msgbox(DateDue)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

arser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

msgbox("A statement fee of $" & FeeAmount & " has been assessed against loan # " & LoanNumber & ".")

Select $5 and click button.

Everything is working. We just need to remember to comment out our last debug message.

'Assess Statement Fee

'By Aaron Abrams

'Today's date

'Activate on button click

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Get Fee amount

FeeAmount = nlsapp.getfield("loan_detail1_udf1")

'msgbox(FeeAmount)

'Zero Fee amount field

nlsapp.setfield "loan_detail1_udf1", "0.00"

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Define variables for XML

LoanNumber = nlsapp.getfield("loan_number")

'msgbox(LoanNumber)

DateDue = nlsapp.getfield("loan_nextintduedate")

'msgbox(DateDue)

'Assess Statement Fee

Set parser = nlsapp.getxmlparser()

parser.intoelem

parser.addelem "NLS", ""

parser.intoelem

parser.addelem "TRANSACTIONS", ""

parser.intoelem

parser.addelem "TRANSACTIONCODE", ""

parser.addattrib "TransactionCode", "500"

parser.addattrib "EffectiveDate", EffectiveDate

parser.addattrib "LoanNumber", LoanNumber

parser.addattrib "Amount", FeeAmount

parser.addattrib "DateDue", DateDue

returnvalue = nlsapp.importXMLrecord(parser.getdoc)

if (returnvalue = false) then

msgbox nlsapp.GetErrorString

end if

'Save and Refresh

nlsapp.savescreen()

nlsapp.refreshscreen()

'Results Message

msgbox("A statement fee of $" & FeeAmount & " has been assessed against loan # " & LoanNumber & ".")

And one last test.

Select $10 and click the button.

Show the fee is in payments due.

We have met all of our objectives with this script. Thank you for watching. If you found this demonstration interesting and helpful, and would like more like it, please let us know, and tell us what types of actions you would like to see scripted, and we will show you what you would like to see.