Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

Need VB Script that puts the value i entered in combobox in to the Json

Hi,
I followed the steps given below and it worked, but I need a VB Script to put the value I entered in that session of the installation and put it in to the json file. Can you please help with this

In order to achieve what you want you can use our "ExtractComboBoxData" predefined custom action to extract all combo box items (extracted in "AI_COMBOBOX_DATA" property). Then, you can create your own custom action wich will parse the "AI_COMBOBOX_DATA" property content and will extract selected item text and value. Also, please keep in mind that a combo box property is always set with its selected item value.

Here are the steps to proceed:
- Go to "Dialogs" page and add your combo box control (e.g. COMBO_PROP).
- Go to "Custom Actions" page and add our "Extract combo box data" custom action without sequence.
- Add a "Launch attached file" custom action without sequence (e.g. ExtractSelectedItem) using a VBS file like this:
CODE: SELECT ALL

Dim comboBox
Dim selectedItemValue, selectedItemText

comboBox = Session.Property("AI_COMBOBOX_DATA")
selectedItemValue = Session.Property("COMBO_PROP")

itemsArray = Split(comboBox, "|", -1)

For Each item In itemsArray
tempItem=Split(item,"#")
If (tempItem(0) = selectedItemValue) Then
selectedItemText = tempItem(1)
End if
Next

Session.Property("COMBO_VALUE") = selectedItemValue
Session.Property("COMBO_TEXT") = selectedItemText

which will save the selected item value and text in two installer properties (COMBO_VALUE and COMBO_TEXT).

- Go to "Dialogs" page and on [Next>] button (of your combo box dialog) add the following published events:
Event: [AI_COMBOBOX_DATA]
Argument: COMBO_PROP

Event: Execute custom action
Argument: ExtractComboBoxData

Event: Execute custom action
Argument: ExtractSelectedItem
- Build and run your project.
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Need VB Script that puts the value i entered in combobox in to the Json

Hello Abhinay,

Unfortunately, I am afraid I am not experienced enough to create a VB Script for you that will add a key:value pair to a .JSON file. However, here is a little PowerShell script that does exactly what you want:

Code: Select all

# the path to your .json file
$jsonfile = 'C:\Users\Catalin\Desktop\catalin.json'
# convert the JSON data to a PowerShell object
$json = Get-Content $jsonfile | Out-String | ConvertFrom-Json
# adds the new key-value pair
$json | Add-Member -Type NoteProperty -Name 'newKey' -Value 'newValue'
# convers the object back to JSON
$json | ConvertTo-Json | Set-Content $jsonfile
You can add this to your project as a "Run inline PowerShell Script".

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Abhinay
Posts: 36
Joined: Wed Feb 27, 2019 9:33 am

Re: Need VB Script that puts the value i entered in combobox in to the Json

Thank you, Its Working fine... :lol: :-)
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Need VB Script that puts the value i entered in combobox in to the Json

You are always welcome, Abhinay.

Glad I could help.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”