Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

const string value as map key?

imants_smidchensimants_smidchens Member Posts: 63 EDU
edited April 2023 in FeatureScript
Hi! I'm working on a featurescript that has a lot of maps for user inputs/calculations, and to keep things clean & organized, I've moved all the maps to a separate feature studio, which I then import.

To make things more robust & future proof, I'm defining some strings (which will be used in keys later) as constants, but unfortunately Featurescript insists that it can't find a key then.

for example:
const a = "foo";
const b = "bar";
export const DemoTable = {
   "name" : "table",
   "displayName" : "table",
   "default" : (a)
   "entries" : {
      (a) : "chose foo",
      (b) : "chose bar",
   }
}

If I use strings for the keys, it works fine, but changing them to variables, even when wrapped in parentheses, results in the Feature Studio that imports these tables saying "Map entry has no key"
supposedly this should be allowed....





any suggestions?

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    It looks correct, other than missing a comma after
    "default" : (a)

    and a missing a semicolon at the end.  Public doc version that shows the error?

    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Your code is fine to use in FeatureScript runtime code, but defining FS parameters (in this case, a lookup table) requires specific syntax, since parameter definitions need to created before the code is run.

    So lookup tables specifically require their maps to be listed with literal string keys, not an arbitrary FeatureScript expression.
  • imants_smidchensimants_smidchens Member Posts: 63 EDU
    Your code is fine to use in FeatureScript runtime code, but defining FS parameters (in this case, a lookup table) requires specific syntax, since parameter definitions need to created before the code is run.

    So lookup tables specifically require their maps to be listed with literal string keys, not an arbitrary FeatureScript expression.
    Gotcha. Thanks for the info!
Sign In or Register to comment.