Custom Field on Labels

CCFS_ZachCCFS_Zach Member Posts: 25

Hello,

I recently read an article on how certain item information can be pulled using javascript in the print templates. Mainly, what I'm trying to do is put our shelf locations for items on the labels so that everything gets put in the right location once it's received.

Based on this article, it appears that it's possible to use the javascript within the print templates and grab specific item information, such as custom fields. That being said, I have a "ShelfLocation" custom field and am trying to grab its information and add to my label.

Here is a link to the article: https://community.lightspeedhq.com/en/discussion/comment/8785#Comment_8785

Also, a user posted their Github with their templates; the label template includes a portion where the custom field is obtained. I tried implementing this portion of the code, but it doesn't seem to return anything (or I'm just not sure how to print the obtained information as text)


Github link:


Additionally, here is the specific code used to attempt to grab the 'Custom Field' information:

                 <script>
                 (async() => {
                    const request = await fetch('https://us.lightspeedapp.com/API/Account/{{ Account ID}}/Item/{{ Label.Item.itemID }}.json?load_relations=["CustomFieldValues"]', {credentials:"same-origin"});
                   const response = await request.json();
                  if(response.Item.CustomFieldValues.CustomFieldValue.name === "ShelfLocation") { document.getElementById("shelflocation").textContent = response.Item.CustomFieldValues.CustomFieldValue.value};
                 })()
                 </script>
<br/>
<div id="shelflocation" class="description">
</div>

If I could just get the tag information and put it on the label, that would work as well.


Has anyone worked with this before? Or does anyone have a suggestion on what I can do?


Thanks,

-Zach

Tags:

1 comment

  • CCFS_ZachCCFS_Zach Member Posts: 25

    As a side note, I did make sure to replace the "{Account ID}" in the link with my Lightspeed Account ID.

Sign In or Register to comment.