# Limit characters from collection

**URL:** <https://community.weweb.io/t/limit-characters-from-collection/640>\
**Category:** How do I?\
**Created:** [June 7, 2022, 2:09pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640 "2022-06-07T14:09:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)\
**Post date:** [June 7, 2022, 2:09pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/1 "2022-06-07T14:09:31Z")

</div>

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?

 ![Screen Shot 2022-06-07 at 10.06.27 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/b968246263aa56eb9799cfd675509e3c4f909e4a.png)

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [June 7, 2022, 3:12pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/2 "2022-06-07T15:12:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)\
**Post date:** [June 7, 2022, 3:54pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/3 "2022-06-07T15:54:45Z")

</div>

thanks, I moved the lines but it didn’t seem to have any impact on shortening the text… perhaps it’s an issue with line 5 itself?

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [June 7, 2022, 4:34pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/4 "2022-06-07T16:34:53Z")

</div>

I think it should be:  
`if (uri.length > 250) { uri = uri.slice(0,250) }`

---

<div class="post-metadata">

**Author:** ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)\
**Post date:** [June 7, 2022, 4:50pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/5 "2022-06-07T16:50:43Z")

</div>

![Screen Shot 2022-06-07 at 12.49.53 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/6c9b25534646d033bdde79e253901b649215dbde.png)  
thanks, that kicked back an error… see screenshot!

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [June 7, 2022, 5:55pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/6 "2022-06-07T17:55:00Z")

</div>

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 || ""`

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [June 7, 2022, 6:24pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/7 "2022-06-07T18:24:07Z")

</div>

Hi @nocodedevs 👋

You can actually do this with the subText no-code formula:

 ![CleanShot 2022-06-07 at 20.22.59@2x](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/1X/818b0a1a5bd99c95bb6237ec70518b34209cc9ae.png)

---

<div class="post-metadata">

**Author:** ![nocodedevs](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nocodedevs](https://community.weweb.io/u/nocodedevs)\
**Post date:** [June 7, 2022, 6:25pm UTC](https://community.weweb.io/t/limit-characters-from-collection/640/8 "2022-06-07T18:25:33Z")

</div>

ok thanks so much!
