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: 

Scripting operations in arrays

6 REPLIES 6
Reply
Message 1 of 7
Stuart_Gray
438 Views, 6 Replies

Scripting operations in arrays

Yo guys, I'm rewriting a condition script that we have which has been timing out regularly.

 

Currently, the condition script dynamically builds an array of users who have performed a particular transition in the workflow.

 

I'm looking to create a physical array on the item details page, that can be used as above (but moving the time required to build the arrays into an action script)

 

What I have in mind is two arrays, "to approve" and "has approved". The condition script then simply looks at the "to aprove" array, and allows multiple transitions to these users. When they perform a transition, I want the action script to remove their name from the first array, and move it to the second.

 

I have been trying to use Array.slice() for this purpose, however I keep getting errors in the script tool. "Cannot find function slice in object"

 

Here is my code:

var usr = Security.loadUser(userID);
var usrName = usr.lastName+", "+usr.firstName;

var toApprove = item.ORIGINAL_APPROVERS;
var hasApproved = item.APPROVED_BY;

    for (var user in toApprove){
        var toApproveMember = toApprove[user];
    	if (toApproveMember === usrName) {
        hasApproved.add(toApprove[user]);
        toApprove.remove(toApprove[user]);
        break;
    	}
    }
 //   println(typeof(toApprove));
 //  var ABCDEFG = toApprove.slice(user,1);
 //  println(ABCDEFG);

Using .add and .remove has allowed me to move the names around the arrays, but the limitation here is that I can't read the length of "toApprove", to determine when there is only 1 approver remaining (who pushes down a different transition from the others).

 

Any Suggestions?

 

Cheers

6 REPLIES 6
Message 2 of 7
gasevsm
in reply to: Stuart_Gray

Hi Stuart,
You could use multiselect picklist for both to:: and has:: arrays and manipulate those. Alternatively, can use a reference to a new 'virtual user group' workspace where each item had multiselect plm with preselect users representing a more or less fixed approver group. The approving item would have a single select picklist pointing to the group item. This wont give you granularity to change the group but can still track has:: and to::: approve in separate lists quiering the linked picklist. HTH,

Martin Gasevski | Fusion 360 Team Product Manager
Message 3 of 7
Stuart_Gray
in reply to: gasevsm

Hi Martin and thanks for the super-quick response!

 

Both my' to..' and 'has..' fields are set as multi-select picklists (specifically, the built-in "Users, all" picklist). I'm wondering whether these field types act and look like array objects, but are in actual fact something else? This would explain why I can't get Array.splice() to work on them.

 

I'll suggest the groups idea to our PLM team, although as this is our supplier enquiry workspace nearly every employee will review a supplier quote at some point and so we need to retain the ability to select specific users per record.

 

Cheers

 

 

Message 4 of 7
gasevsm
in reply to: Stuart_Gray

Yes they are FLC arrays but not JS arrays, hence splice() limitation. Let me see what i find on my side.

Martin Gasevski | Fusion 360 Team Product Manager
Message 5 of 7
Stuart_Gray
in reply to: gasevsm

Cool, thanks Martin. 

 

I can get around it other ways, for example I can compare the array length of the approved users to the original. It will mean the code has an extra line to compare the values, but I can't imagine it'll add any noticeable time on. I'll report back once I'm done,

 

Cheers

Message 6 of 7
gasevsm
in reply to: Stuart_Gray

http://help.autodesk.com/view/PLM/ENU/?guid=GUID-BBBBAB3B-FEAE-4EB7-8D1B-29E76EC6BC65


* To add individual items, use item.LINKING_MULTISELECT.add(someItem)

* To remove individual items, use item.LINKING_MULTISELECT.remove(someItem)

* To clear the array, use item.LINKING_MULTISELECT.clear()

Martin Gasevski | Fusion 360 Team Product Manager
Message 7 of 7

Hey Stuart,

 

Instead of:

 //   println(typeof(toApprove));
 //  var ABCDEFG = toApprove.slice(user,1);
 //  println(ABCDEFG);

What about converting that object into an array with this, so you can use the Array methods?:

 

var convertedToApproveArr = Object.keys(toApprove).map(function (key) {
     return toApprove[key];
});

println(convertedToApproveArr);
var ABCDEFG = arr.slice(user,1);
println(ABCDEFG);

Let us know how it goes.

 

Cheers,

 

Giliar


Giliar de Fries Perez
Sr. Product Owner
Fusion 360® Manage
Autodesk Canada Co.

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

Post to forums  

Autodesk Design & Make Report