NetSuite: Automatically Create TAX Nexus for all USA and Canada States

Code is not perfect and is not production ready.

  1. Iterate through the List of States vs Countries
  2. Create the Tax Nexus using the internal ID of the state for the RecordRef
//FOR USA AND CANADA STATES
      Iterator statesIterator = stateMapUSAAndCanadaForNexusCreation.entrySet().iterator();
    int ctr = 1;
    System.out.println("Total Size " + stateMapUSAAndCanadaForNexusCreation.size());
      while (statesIterator.hasNext()) {
          Map.Entry countryVsState = (Map.Entry)statesIterator.next();
          if(countryVsState.getKey().equals(Country._unitedStates)){
          	System.out.println("Creating Nexus:" + ctr + ", Country: " + countryVsState.getKey().toString() + "United States"+ ", State" + (String)countryVsState.getValue() );
          	createNexus((Country)countryVsState.getKey(),"United States",(String)countryVsState.getValue());
          	
          }else{
          	System.out.println("Creating Nexus:" + ctr + ", Country: " + countryVsState.getKey().toString() + "Canada"+ ", State" + (String)countryVsState.getValue() );
          	createNexus((Country)countryVsState.getKey(),"Canada",(String)countryVsState.getValue());
          }	
          statesIterator.remove(); // avoids a ConcurrentModificationException
          ctr++;
      }

public void createNexus(Country countryCode, String countryName, String stateName, String stateInternalID) throws Exception{
    //this.login(true);
    //sub.setNexusList(nexusList);
    //getCountryList();
    
    RecordRef state = new RecordRef();
    state.setType(RecordType.state);
    state.setName(stateName);
    state.setInternalId(<Get it from the List>);
    
    Nexus nex = new Nexus();
    nex.setCountry(countryCode);
    nex.setState(state);
    
    nex.setDescription(countryName);
    
    // Invoke add() operation
    WriteResponse response = _port.add(nex);
    // Process the response
    if (response.getStatus().isIsSuccess()) {
      _console.info("\nNexus Created for :" + countryCode.getValue()
          + "\n  key="
          + ((RecordRef) response.getBaseRef()).getInternalId()
          + "\n  entityId="
          + nex.getDescription()
          );
    } else {
      _console.error(getStatusDetails(response.getStatus()));
    }
  }

List of States are here (Please get your own internal Ids)

// GET YOUR INTERNAL IDS
private static final Map<Country,String> stateMapUSAAndCanadaForNexusCreation;
  static{
    stateMapUSAAndCanadaForNexusCreation = new HashMap<Country, String>();
    
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Alberta");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"British Columbia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Manitoba");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"New Brunswick");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Newfoundland");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Nova Scotia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Northwest Territories");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Nunavut");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Ontario");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Prince Edward Island");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Quebec");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Saskatchewan");
    stateMapUSAAndCanadaForNexusCreation.put(Country._canada,"Yukon");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Alabama");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Alaska");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Arizona");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Arkansas");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"California");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Colorado");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Connecticut");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Delaware");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"District of Columbia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Florida");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Georgia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Hawaii");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Idaho");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Illinois");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Indiana");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Iowa");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Kansas");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Kentucky");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Louisiana");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Maine");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Maryland");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Massachusetts");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Michigan");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Minnesota");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Mississippi");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Missouri");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Montana");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Nebraska");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Nevada");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"New Hampshire");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"New Jersey");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"New Mexico");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"New York");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"North Carolina");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"North Dakota");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Ohio");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Oklahoma");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Oregon");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Pennsylvania");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Puerto Rico");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Rhode Island");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"South Carolina");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"South Dakota");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Tennessee");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Texas");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Utah");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Vermont");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Virginia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Washington");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"West Virginia");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Wisconsin");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Wyoming");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Armed Forces Europe");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Armed Forces Americas");
    stateMapUSAAndCanadaForNexusCreation.put(Country._unitedStates,"Armed Forces Pacific");
    
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>