Bool parameter becomes a string when set via initialParameterValues

Hello,

I’m creating a session in JavaScript and passing one initial Bool parameter

const createdSession = await createSession({
    ticket: shapeDiverTicketId,
    modelViewUrl: MODEL_VIEW_URL,
    id: "shapediver-session",
    initialParameterValues: { "Underline": "true" },
});

I’m then logging the names, values and types of the parameters in that created session

Object.values(createdSession.parameters).forEach((param) => {
    if (param.type === "Bool") {
        console.log("param.name", param.name, "param.value", param.value, "typeof param.value", typeof param.value);
    }
});

The output log:

param.name Height/Lenght Priority param.value false typeof param.value boolean
param.name Italics param.value false typeof param.value boolean
param.name Custom Font param.value false typeof param.value boolean
param.name Show Dimensions param.value false typeof param.value boolean
param.name Absolute/Relative Line Spacing param.value false typeof param.value boolean
param.name Merge Characters param.value true typeof param.value boolean
param.name Underline param.value true typeof param.value string
param.name Bold Text param.value true typeof param.value boolean

Notice that the value type of Underline which is a Bool parameter becomes a string. This always happens when value of the Bool parameter is set in the initial parameters dictionary.

Is this intentional?

i changed the category to shapediver - hopefully that s correct - change it to something else if i am wrong - good luck for a fast solution.

1 Like

Hello @Sebastian_Meckovski !

Thank you for your question.

This behavior is currently intended, as you can set all parameter values in the API as a string as well to their defined type (they are stringified either way when being sent to our servers). In your case, the parameter values are therefore directly set to what was provided in the `initialParameterValues`. As I completely get that this might be a bit unexpected in this case, I’ll file a task so that these values can be parsed correctly.

I’ll get back to you once that is done.
For now you could work around this by checking the parameter type instead and then parsing the values.

Cheers, Michael

@MajorMeerkatThe3rd Thanks!

The confusing part is that that initialParameterValues property accepts only [key: string]: string;. Makes it confusing when using non string type parameters.

Would be nice if it could map to [key: string]: IParameterApi or something like that

Although I implemented a workaround to convert from “true” string to true bool so I solved the issue for bool values on my end

Hello @Sebastian_Meckovski ,

this issue has been resolved in viewer version 3.14.0.

Cheers, Michael