I've upgraded to Ops Hub and want to understand the best way to clean up / format domains when they're submitted via form.
For context, we have several custom objects created via forms, and the domain seems to be the best feild to associate them all (pls correct if I'm mistaken here). That said, folks will submit domains that slightly differ than what HS has on file at the Company level, (ex: including or excluding http://) so I need to make everything uniform arross the board.
What is the best way to do this using the Format function in Ops Hub?
happy to help you out here. This should be effortlessly possible with a short custom code workflow action. Since you mentioned Ops Hub you should be able to create one.
I've created a short Python script for you. Please let me know if you need help implementing that.
from urllib.parse import urlparse
def main(event):
url = event.get("inputFields").get("url")
parsed_url = urlparse(url)
domain = parsed_url.netloc.split(".")[
-2:
] # Extract the last two parts of the domain
return {
"outputFields": {
"domain": ".".join(domain),
}
}
No matter how the URL looks like, the method urlsparse provides the opportunity to just leave with the domain name and TLD (so. example.com)
Make sure you load the URL you want to adjust as an input field with the name url and provide an output field called domain. After that, you can use the Copy Property Value action to copy the output into another property.
Hope that helps. If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I'd really appreciate it.
I'd like to ask our top experts about some tips they may have: Hi @Teun, @louischausse and @ChrisoKlepke can you share information to help @JKenler, please?
Also, if anybody else has anything to add and/or share, please feel free to join in the conversation 🙂
happy to help you out here. This should be effortlessly possible with a short custom code workflow action. Since you mentioned Ops Hub you should be able to create one.
I've created a short Python script for you. Please let me know if you need help implementing that.
from urllib.parse import urlparse
def main(event):
url = event.get("inputFields").get("url")
parsed_url = urlparse(url)
domain = parsed_url.netloc.split(".")[
-2:
] # Extract the last two parts of the domain
return {
"outputFields": {
"domain": ".".join(domain),
}
}
No matter how the URL looks like, the method urlsparse provides the opportunity to just leave with the domain name and TLD (so. example.com)
Make sure you load the URL you want to adjust as an input field with the name url and provide an output field called domain. After that, you can use the Copy Property Value action to copy the output into another property.
Hope that helps. If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I'd really appreciate it.