hey everyone! I am getting data from an API and now I want to allow the user to Tweet the result.
It’s working (thanks to this community) but I now need to limit the # of characters that can be sent to Twitter since the max is 280.
I’ve posted a screenshot of the JS connected to the button where I am trying to limit the # of characters. It’s not giving me an error but it also doesn’t seem to be working. Any tips?
I am on my phone now but it looks like you are returning the original unchanged value.
Line 3 you are encoding the uri variable and assigning it to the encoded variable.
Line 5 you check the length of uri and assign a different value, but encoded is unchanged by this ooeration.
Line 7,9 your return value is calculated from the variable encoded that is still unchanged.
Try moving the code on line 3 after the code on line 5.
On a side note “uri” and “url” are very easy to misstype, you can try to use more specific and different names.
From your code the assumption is that uri is a string. You need to decide how to handle the case of uri being undefined as in this case.
You can decide not to run the workflow at all or you can return a default value. You can add this logic with weweb formulas too.
Without knowing the context of your workflow I can suggest only partial solutions. A dirty quick fix can be to add uri = uri || ""