Script too long

Script too long

PLM-Sylvain.Bailly
Collaborator Collaborator
1,209 Views
3 Replies
Message 1 of 4

Script too long

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hello,

 

I have a big problem in one of our script, a very important one because it avoids lot of manual work for our data manager. This script in an action script at the end of the Change Request workspace. Basically, it creates a change order in the Change Order workspace and copies/pasts all the affected items of the change request to the new change order generated.

 

The script is too long when you have more than 70 items in the affected items tab. I remember that a script cannot exceed 8 seconds or it fails (but it is an old memory from my FLC training). Here the script ran 10s (see attachment).

 

I have check different topics about it but there is no solution:

 

Put the following script in the library does not solve it:

// We create an Item Change Order only if it is needed  
function closeItemsDR(){
    if(item.RELATED_CHANGE_ORDER === null){

            var newProperties = [];
            newProperties.TITLE = item.TITLE;
            newProperties.RELATED_DESIGN_REVIEW = item;
            var newItem = createNewItem('WS_CHANGE_ORDERS', newProperties);
            item.RELATED_CHANGE_ORDER = newItem;
            
            // loops through all the related items and adds that item to the managed items tab of the ECO
            for (i = 0; i < item.relationships.length; i++) {
                newItem.workflowItems.addItem({RELATED:item.relationships[i].item});
            }
    }
}

 

Thank you for your help,

Cheers,

Sylvain

0 Likes
Accepted solutions (1)
1,210 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

Hello,

 

We got around script timeouts by first querying the grid length. If it was longer than a specified amount that we know can successfully spawn (for example, 8 records) then run a for loop to this maximum amount ( or 1...2 less so you still have scripting time available). Once complete, write this value to a field on item details, and then get the script to perform workflow transition.

 

Create a new closed loop transition on the state (which the first script runs), and have another almost-identical script attached to it, that starts its for loop from the stored item details variable from earlier. Run through your specified amount again (8), and rinse, repeat for as many records as you need.

 

Obviously not scalable after a point, but I've successfully got 3 transitions daisy-chained to run scripts on lists around 140 records long.

 

Hope that makes sense. 

Message 3 of 4

Anonymous
Not applicable

The 9s script time out issue is a pain but I understand why it's there.

 

We face the same issue as everyone else here.  In our records we attach 60+ drawings.  Each drawing represents an item for manufacture which we want to track with workflows...so we create 60+ records in a single transition.

 

The only way I've tried to get around this is to piggy back some library scripts, and trying to improve my code efficiency.  I offloaded milestone creations for each new item which has helped but in the end, we still hit the time out errors still.

 

 

Message 4 of 4

PLM-Sylvain.Bailly
Collaborator
Collaborator

Hi,

 

Thank you for your answers. I saw your post about it but like you, I need to migrate most of the time around 120-180 items. Each item contains a drawing and a stp file.

It would be good to have, as admin, the right to tune the timeout. I think that 15sec can solve lot of our problems.

 

I will configure a library script and if it doesn’t work because the items are too important, do a closed loop transition.

 

Thank you guys,

Cheers,

Sylvain

0 Likes