Thursday, February 28, 2019

Calculations with Adobe Forms radio buttons

 Calculating Adobe Forms


Its been a long while since I've blogged.  I had an interesting small project land on my desk that required calculating values based on radio buttons in an Adobe form.  Initially, I figured this was a simple task that any office worker with intermediate knowledge could do.  After digging into it farther I discovered Javascript had to be used for anything more than a simple sum, product, average, minimum or maximum. 

The thumbnail picture at the beginning of this blog is just a small part of the form I had to work on.  In this blog post, I will create a 5x4 table with radio buttons.  At the bottom, I will sum the choices based on their value. Then I will find the sum of all the columns and find the mean of the choices.

I started out by creating a basic document in Microsoft Word.
Test PDF form image

After creating the PDF, I added the form fields and radio buttons.  The group names were Question1, Question2, etc.  Each button had the Radio Button Choice set to a unique value for each button group. For instance Question 1, and Question 2, both had 4,3,2,1, and 0.

Test PDF From with form buttons and boxes imageTest PDF Form Fields sidebar image


That value was set by either right-clicking the button and selecting Properties or double-clicking the option under the question and entering the value.
Test PDF Form radio button options image
 After the radio buttons were set, I added simple text boxes for each column. Lastly, I added a Sum box and a Mean box.

Now that the form fields exist on the form, it is time to start adding the calculations.

I started with the first column, the 4s column.  I went into the properties of the Total4s text box. I selected the Calculate tab, chose the "Custom calculation script", and clicked Edit.

This is the way I choose to calculate the values. I am certain there are other ways to accomplish this but this method seemed the most straight forward and scalable option for less tech-savvy users.



The first variable total4s is how we will track the number of buttons selected in the 4 column.  I set it to 0 to make sure we are starting from the same place every time.  Next, I use this.getField("Question1").value to get the value of the button selected.  If the radio button in column 4 on Question 1 is selected, the value will be 4 based on the "Radio Button Choice" field referred to earlier.  In my initial testing, I set the value to a variable. I then had the if statement evaluate based on that variable.  After working to simplify the script, I realized I was able to evaluate the getField value directly.

Next, I entered the same code in for each Total3s, Total2s, Total1s, and Total0s.  I modified the variable total4s to match the text box for each column (Total3s = total3s, Total2s = total2s, etc.).  I also changed the condition value in the if statement to match the column number.

After entering the similar javascript in each text box I can test if I receive the expected value.
If the values aren't as expected, you may need to check the Field Calculation Order. The order is top down.  For instance if a calculation depends on a previous calculation, the dependent calculation should be higher in the list.  In this example, the Total*s must calculate before the sum and lastly the mean.


Now I will choose Preview so I can verify I am getting the expected.


At this point, the value only shows a 1 for each selection.  For my needs, I want each selected column to have the value of that column in the total.  So I would like any buttons in the 4 column to return 4 for their total and add up as buttons are selected.  The way I did this was simply by taking the final line of the code event.value = total4s and multiplying it by the column value. Below is what I changed for the last line in each text box.  For the 0 column text box, I don't have any calculations and set the default value to 0.



The next part is adding up the values. Fortunately, we are able to do this with built-in calculations. From the Properties > Calculate tab, I chose "Value is the" and left the default as "sum (+)". When choosing that field, the "Pick" button becomes active.  I chose Total4s, Total3s, Total2s, and Total1s.  Since Total0s will always be 0, I don't need to include it.


Next, I will find the mean.  For that, I'm able to use another option in the Calculate tap under properties for a text box.  "Simplified field notation" is the perfect solution to this.  I just entered TotalSum/4.


After all that, the final product


Wednesday, February 27, 2019

Powershell - Group Policy

A new project came up for me that involved rebuilding our System Center Configuration Manager servers. Being a small environment, our Config Mgr server hosts our WSUS role. Once that server was up and running my next task was to switch over all our clients to the new server. The existing group policy objects weren't best practice and didn't meet our organization requirements. Initially I was planning on reusing the old objects but decided to just scrap them.

The first step was to remove the links using commands similar to this:

 Remove-GPLink -Name "WSUS-OldPolicy" -Target "OU=TargetOU,DC=domain.DC=com"   

I ended up copying this line and changing the Target for each OU I wanted to remove it from.  I also could have read a csv full of the OUs if there was going to be a lot.  I had issues with the Target syntax that I couldn't seem to figure out.  I ended up opening the properties of the OU in ADUC and viewing the distinguishedName.

If I wanted to remove the policy completely I could have run:

 Remove-GPO -Name "WSUS-OldPolicy"  

I typically don't delete policies right away so I'll save that for later.  Running the Remove-GPO cmdlet will also remove the links.

The next step was to create a new policy.

 New-GPO -Name "WSUS-NewPolicy"  

Once the policy is created you can link it to the OU that needs it.

 New-GPLink -name "WSUS-NewPolicy -target "OU=TargetOU,DC=domain,DC=com"  

A shorthand to combine the commands and only need to link it to one place would be:

 New-GPO -Name "WSUS-NewPolicy" | GPLink -target "OU=TargetOU,DC=domain,DC=com"  

Now that the GPO has been created and linked.  You can edit it to the configuration you want.

*Note: I typically don't link GPOs until after they have been configured.  Then I link them to my test OU and test them.  After those steps do I finally link them to production OUs and I typically start with a couple lower priority ones, then link it to all production OUs.