If you are using Google Places integration, the field mapping for state returns as the full state name. We can use a custom script to get the 2 letter state abbreviation.

Step 1: Make sure that you are mapping the state to your {state} custom field. This is done under Data Validation > Third Party Address Validation.

Step 2: Create a custom field called {state_ab} under Admin > Custom Fields (Use text type)

Step 3: Create a node level script on your form node or Q&A node with address and set to run on Exit. We also recommend using a transition node and create enter script.

Step 4: Copy paste this script:

<script>
  // Function to convert state name to 2-letter abbreviation
function convertStateToAbbreviation(stateName) {
  // Object mapping state names to their abbreviations
  const stateAbbreviations = {
    'alabama': 'AL',
    'alaska': 'AK',
    'arizona': 'AZ',
    'arkansas': 'AR',
    'california': 'CA',
    'colorado': 'CO',
    'connecticut': 'CT',
    'delaware': 'DE',
    'florida': 'FL',
    'georgia': 'GA',
    'hawaii': 'HI',
    'idaho': 'ID',
    'illinois': 'IL',
    'indiana': 'IN',
    'iowa': 'IA',
    'kansas': 'KS',
    'kentucky': 'KY',
    'louisiana': 'LA',
    'maine': 'ME',
    'maryland': 'MD',
    'massachusetts': 'MA',
    'michigan': 'MI',
    'minnesota': 'MN',
    'mississippi': 'MS',
    'missouri': 'MO',
    'montana': 'MT',
    'nebraska': 'NE',
    'nevada': 'NV',
    'new hampshire': 'NH',
    'new jersey': 'NJ',
    'new mexico': 'NM',
    'new york': 'NY',
    'north carolina': 'NC',
    'north dakota': 'ND',
    'ohio': 'OH',
    'oklahoma': 'OK',
    'oregon': 'OR',
    'pennsylvania': 'PA',
    'rhode island': 'RI',
    'south carolina': 'SC',
    'south dakota': 'SD',
    'tennessee': 'TN',
    'texas': 'TX',
    'utah': 'UT',
    'vermont': 'VT',
    'virginia': 'VA',
    'washington': 'WA',
    'west virginia': 'WV',
    'wisconsin': 'WI',
    'wyoming': 'WY',
    'district of columbia': 'DC'
  };

  // Handle potential variations in input
  const normalizedState = stateName.trim().toLowerCase();
  
  // Return the abbreviation if found, otherwise return the original state name
  return stateAbbreviations[normalizedState] || stateName;
}

const state = "{state}";
const stateAbbreviation = convertStateToAbbreviation(state);

// Output the result to console
console.log(stateAbbreviation);
DT.setField('state_ab', stateAbbreviation);
</script>

Step 5: The value will be saved to your {state_ab} custom field