Start a new topic
Answered

InputBox variable across all records

Good afternoon,


Over the last couple of months I've been tinkering with the IOM API to do a few things that were niggling me (we had around 20,000 records with an alias that shouldn't have been there and was interfering with legit alias searches). I have a background in VB and a little Python so it's been mostly getting my head around some of the syntax.


I've just finished a little piece of code to record Return to Senders a little better - rather than put a flag or attribute on the constituent, it should be the address (specifically the preferred address) that gets marked as being bad, as people often have multiple addresses. It's probably not the most elegant, but it works and it's taught me a little more about the language.


What I do want to do is factor in an interactive element, specifically being able to set a variable without having to go in and change it using a static field (and potentially forget to change it back) - that way I could specify that the batch of RTS ConIDs were from a specific Appeal or purpose, and have it record Appeal outcomes and so on. So I tried doing an import.fields.getbyexcelname() = inputbox function on a different import profile to record mailing outcomes, so that I could, for example, run three imports back to back from different dates and backdate them all accurately. Of course, what happened was an inputbox trying to popup for each and every one of the 7000+ lines...


So I'm looking for one of two answers - can I get a single popup at the start of the import that sets the variable and can have the other subs access it for the rest of that upload (and only that upload... and only that profile for that matter). Or, is there a way to have a single popup take a value and change the upload profile itself to set the value for a static field?


The former is much better, but basically any way to get a single input to apply a value to all rows. It would only be me running it, and I use validation out of paranoid habit so the validation isn't as much of a concern as it might be out in the wild, but I'd be able to write in some checks and balances just in case.


Thanks in advance,


Adam


Best Answer

Hi Adam,


You were on the right track, it sounds like you just had your input box in the wrong location.  You'll want the input box in the before import section.  Here's a simple example:


Public Class Profile

    Inherits ImportOM.API.ProfileBase

 

 Private _variable As String = String.Empty 'declare your variable

 

#Region "IOM Events"

    Public Overrides Sub BeforeImport(ByVal Cancel As ImportOM.API.iCancel)

        'Import has not been started yet

 

  _variable = InputBox("Enter your variable") 'assign value to variable

 

    End Sub

    Public Overrides Sub BeforeComputedColumns(Cancel As ImportOM.API.iCancel)

        'Raw data straight from the file

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"

 

    End Sub

    Public Overrides Sub BeforeDictionaries(Cancel As ImportOM.API.iCancel)

        'The data row at this point has generated computed columns

        'but hasn't gone through dictionaries.

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"

 

    End Sub

    Public Overrides Sub AfterDictionaries(Cancel As ImportOM.API.iCancel)

        'The data row at this point has gone through dictionaries

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"


        'If you've assigned a value to the variable then do something


        If _variable <> String.Empty Then

        Import.Fields.GetByExcelName("B").Value = _variable 'Use the variable

        End If

 

    End Sub



Thanks,


John



Answer

Hi Adam,


You were on the right track, it sounds like you just had your input box in the wrong location.  You'll want the input box in the before import section.  Here's a simple example:


Public Class Profile

    Inherits ImportOM.API.ProfileBase

 

 Private _variable As String = String.Empty 'declare your variable

 

#Region "IOM Events"

    Public Overrides Sub BeforeImport(ByVal Cancel As ImportOM.API.iCancel)

        'Import has not been started yet

 

  _variable = InputBox("Enter your variable") 'assign value to variable

 

    End Sub

    Public Overrides Sub BeforeComputedColumns(Cancel As ImportOM.API.iCancel)

        'Raw data straight from the file

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"

 

    End Sub

    Public Overrides Sub BeforeDictionaries(Cancel As ImportOM.API.iCancel)

        'The data row at this point has generated computed columns

        'but hasn't gone through dictionaries.

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"

 

    End Sub

    Public Overrides Sub AfterDictionaries(Cancel As ImportOM.API.iCancel)

        'The data row at this point has gone through dictionaries

        'Use the Fields object to access the data

        'Example: Import.Fields.GetByExcelName("D").Value = "New Value for D Column"


        'If you've assigned a value to the variable then do something


        If _variable <> String.Empty Then

        Import.Fields.GetByExcelName("B").Value = _variable 'Use the variable

        End If

 

    End Sub



Thanks,


John



1 person likes this

In BeforeImport you can pop up the prompt and set a global variable.


Or you could set the value of a blank virtual field dynamically and then check if it's filled in before prompting again.


You can write new objects into the VB script outside the functions which are global.


1 person likes this

Thank you very much, I think it was a problem with the sequence, it was saying originally that I couldn't transfer the variable between the subs, but this works. Much appreciated.

Login to post a comment