Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Comparing a Pick List to a string with the "===" operator

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Andrew.Shaw
636 Views, 1 Reply

Comparing a Pick List to a string with the "===" operator

I'm trying to compare the content of a Pick List to a string in a script using the "===" operator but the result is always false. What am I missing?



Andrew Shaw
Premium Support Specialist PLM/PDM
Global Services
Autodesk, Inc.

1 REPLY 1
Message 2 of 2
Andrew.Shaw
in reply to: Andrew.Shaw

Comparison operators are used in logical statements to determine equality or difference between variables or values. Therefore, it is very important to understand data types when you try to access PLM 360 fields through scripting.

 

Let’s take a simple example:

You’ve created a workspace where users can save training webinars. One of the fields is a Pick List from which the user has to select the author of the webinar (the Pick List gets its data from another workspace). A workflow manages the various states the webinar has to go through before being made public and transitions have precondition scripts that restrict them to specific groups, i.e. only the author or his/her manager can transition from state C to state D.

 

So, you’ve written a script such as this:

 

var author = item.AUTHOR;

var user1 = Security.loadUser(login);

var authorCheck = user1.lastName + ", " + user1.firstName;

 

if (Security.inGroup(userID,'Manager')===true){

    isOK = true;

}   else {

        if (author === authorCheck) {

            isOK = true;

        }   else {

                isOK = false;

            }

    }

returnValue(isOK);

 

This script will always return isOK as false and finding the reason can be a bit tricky. The culprit here is the data type of the “author” variable. Logic would tell you that a Pick List will return a string but that is true only if said Pick List gets its data from defined values. In other cases, the data type returned is Object.

 

So, to make your script work, you need to modify the script like this: var author = String(item.W_AUTHOR);.

 

To help you out for your next scripts, here’s a table that shows the data type of each field type:

 

DataTypes.png

 

If you want to run your own tests, here’s the script you need: println(typeof (item.FIELD_NAME));

 



Andrew Shaw
Premium Support Specialist PLM/PDM
Global Services
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report