JavaScript to Transform State Names to State Two Character Code
I just learned that I may need to transform state names into their two digit state code (i.e. Nebraska to NE).
In order to minimize my work effort on this, could I do a JavaScript on the Import filter since the same import is used across many flows? I really want to avoid touching all of the exports (webhook) as I have quite a few and would take me a considerable amount of time. I would love to add another field in the PrimaryMemberInformation section called “StateCode” and that could be used for the import.
Here is a sample payload:
{
"FormInformation": {
"FormName": "Test Form",
"SubmitDate": "2024-02-15T21:39:42.288Z",
"FormId": "326-2",
"FormURL": "https://www.test.com",
"Status": "Submitted"
},
"PrimaryMemberInformation": {
"FirstName": "TestFirst",
"LastName": "TestLast",
"MiddleName": null,
"MiddleInitial": "H",
"NamePrefix": "Mr.",
"NameSuffix": "Jr.",
"DateOfBirth": "1980-01-01",
"SocialSecurityNumber": "111-22-3333",
"Gender": "Male",
"TobaccoUser": "No",
"Relationship": "Self",
"Email": "test@test.com",
"MobilePhoneNumber": "(342) 342-3423",
"CompanyPhoneNumber": "(342) 342-3423",
"StreetAddress": "12345 Test Street",
"AddressLine1": "12345 Test Street",
"AddressLine2": "null",
"AddressLine3": null,
"City": "Omaha",
"State": "Nebraska",
"ZipCode": "44556"
}
}
0
Comments
I would probably do it with a pre save page script, input filter scripts aren't the right place to modify data.
Dave,
I see that you said you want to create a NEW field called stateCode but my thought is that you may not have to do that.
Since you would have to base that field off of something in the import data (such as the State field) I would suggest you just create a static lookup on the import field where you setup the import. Since you said you use the SAME import across multiple flows that static map would apply to all flows.
Is there a particular reason you were thinking of using a script?
Kelly - Great minds think alike and that is what i wanted to do originally. Unfortunately due to how our SF environment is built for this particular field (beyond my level of knowledge) this field doesn't return values that I can use. That said, your idea is how I had originally intended to approach it, but think I have to go with the script on this as the state must be imported as a two-character state! :)
Steve Klett Dave Guderian Assuming you're going with a script, wouldn't a preMap script would be the best place to put this if you are only modifying the data for the one import?
Also, I believe you should be able to ignore the dropdown on that static lookup and just enter your own values in the box. I'm not too familiar with the Salesforce imports, but NetSuite mappings do a similar thing.
Ezriah - You are right! I had no idea that could be done on the import. I think this may be the way I go after all.
Thanks everyone for the help on this!
I wanted to close the loop on this. I ended up needing to go with the Java Script to do this.
Ezriah - When I tried to “Save” after deleting the pre-populated values from Salesforce and putting in my own it would randomly default to a value from the list and delete what I put in. Its possible the NetSuite import works differently, but unfortunately that didn't end up working in my case.
Please sign in to leave a comment.