Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help writing a script (solved)

Featured Replies

I have three tables

Products: id, name, category_id, description

Categories: id, html_template

CategoryFields: id, category_id, key, value

The relationships have all been setup properly.

In Categories::html_template I will have something like this


{name}

  • {size}
  • {length}
  • {width}




now each of the keys (name, size, lenght & width) will be entered via the CategoryFields table.  So every Category will have a different set of keys.



Inside the Products table I set they key values using a portal.



For example

name = "T-Shirt"

size = "M"

length = "50cm"

width = "100cm"



I have a button that will copy the Categories::html_template into Products::description.  I then need it to do a "find and replace" on all the CategoryFields keys (and appending the "{" and "}" ) and then replacing it with the values.



So in the above example, the result would be





T-Shirt

  • M
  • 50cm
  • 100cm

I got this working for fields references inside the products table but am unsure about how to loop over all related CategoryFields.

What script steps should I use to loop over all related records, perform the find and replace and then exit when there are no more keys to replace?

Edited by Guest

Inside the Products table I set they key values using a portal.

For example

name = "T-Shirt"

size = "M"

length = "50cm"

width = "100cm"

A portal to which table?? Perhaps it would be better if you post an example file.

  • Author

Well this really sucks but I can't get the size of the file below 1.05M which is required to upload to this site.

I have even tried zipping with and creating a clone with no success.

The Administrators really need to change the upload limit!!

  • Author

@comment you can download it from here http://droidprofessor.com/tmp/ebayInventory.zip

The script I am editing is called "Product Description from Template"

If you go into the products layout you can run it by pressing the button

Edited by Guest

Something doesn't make sense here: are ALL products in the 'T-Shirt' category of the SAME size, length and width? If yes, why isn't the Description field in the Category record?

  • Author

I was just looking at that myself and thinking that I should reference the products table, not the category table.

:)

I will fix it and upload the link, just give me a second

  • Author

mmmm

come to think of it that will not work either... any ideas?

  • Author

Almost, but what I want if for the Category to control fields. So if I choose a category of T-Shirt, the available fields will display automatically. I could have 100 different products of type T-Shirt and all would share the same keys, however the values would be different for each product.

Well, that's an entirely different issue. One way to do this is to script the creation of new product records, and create the required related records at this time.

  • Author

@comment I have fixed that problem and now I am back at the initial question, looping through all the related records and replacing the key with the value.

I put the new file back up at

http://droidprofessor.com/tmp/ebayInventory.zip

I am back at the initial question, looping through all the related records and replacing the key with the value.

Doesn't my file do just that?

  • Author

oh, so it does - thanks

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.