Calling Validation Script from an Action Script

Calling Validation Script from an Action Script

Anonymous
Not applicable
1,175 Views
10 Replies
Message 1 of 11

Calling Validation Script from an Action Script

Anonymous
Not applicable

As I pointed out here, there is no way to set the default quote from a script.  Therefore, I would like to send a message to the user letting them know that they need to choose a default quote.  A standard Javascript alert would be completely sufficient for this; however, since that function isn't available, I'm trying to come up with an alternative solution.  This forum post suggests using a validation script to do this; however, I haven't been able to figure out how to call a validation script from my action script.  There might be other ways to get the validation script to run after the action script has finished, but I haven't been able to figure out how to do that yet, and honestly, it seems like a basic necessity of any scripting tool to be able to call one script from another.

0 Likes
Accepted solutions (2)
1,176 Views
10 Replies
Replies (10)
Message 2 of 11

gasevsm
Alumni
Alumni
Hi Tim,
You cannot call a validation script from an action script. Validations run before action scripts when the user transitions a workflow action. This is where you can return a message to the user if quotes are not set as default. If it passes validation, then the wf action would transition followed by running of an action script lastly. Hope this helps,
--
Martin Gasevski | Product Manager | Autodesk PLM 360

Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 3 of 11

gasevsm
Alumni
Alumni
I should add, to set this up : open the workflow editor and edit the wf transition of interest. Then, set the validation script (that checks for nondefault quotes and returns appropriate message to user via returnValue(array[]) and save your changes.

Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 4 of 11

Anonymous
Not applicable
So how can I send a message to a user from an action script?
0 Likes
Message 5 of 11

gasevsm
Alumni
Alumni
Cannot be done via action script - not sure where you read this is possible. Only validation scripts can send a message array to user effectively interrupting the WF transition request all together.
--
Martin Gasevski | Product Manager | Autodesk PLM 360

Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 6 of 11

Anonymous
Not applicable

Sorry for not making that clear.  I just expected it to be possible, since I've never heard of a situation where a program wasn't able to provide feedback to the user about actions they had performed before.  This seems like one of the most basic necessities of any programming language.  As I think should be clear from the explanation above, my reasons for needing to do this are unavoidable, as far as I can tell (if anyone knows of a workaround, please let me know).  PLM 360's scripting tools do not have the capability to do something that needs to be done for all of a part's pricing information to be included in the BOMs it is included in.  Therefore, I really don't want to depend on the user remembering that they need to do this themselves (because they are bound to forget at some point), and I really need to give them some sort of message reminding them that they need to do this (and yes, emailing them a reminder is completely inadequate).

0 Likes
Message 7 of 11

gasevsm
Alumni
Alumni

Hi Tim,

 

Your requests are noted, both manipulating default quotes via script and interrupting an action script. Both have been discussed and somewhat specced in past and both are being reviewed in context of future development. Thank you for raising their importance

 

Since neither are planned for near term, I'd like to work together on this for I know the tool is capable today of notifying users of not setting default quote before proceeding. This can be done via Validation script that verify whether your conditions and requirements have been met before allowing a workflow transition to proceed. If this is not met, it has ability to provide UI messagging to end-user for a chance to course correct before attempting again.

 

Having said this, kinldy review this documentation on how to go about doing it, and contact me in private so we can implement it together if still are having reservations on proceeeding;

 

  1. Basic Scripting Concepts; please focus on Validation scripts section. 
  2. Creating Validation Script
  3. Setting Validation Script to a given WF Transition. 
  4. Sourcing Tab Scripting Reference, which you already familiar with.
  5. Validation Script Examples of bubbling up messages to user in the UI.

 

 

Hope this helps and hope to hear from you,


Martin Gasevski | Fusion 360 Team Product Manager
Message 8 of 11

Anonymous
Not applicable
Accepted solution

So I just figured out that it actually is possible to run a validation script from an action script.  In order to do this, you need to create the workflow as if it were going to be used manually, and then you can use the following to perform the workflow transition automatically:

 

item.performWorkflowTransition(transID, 'COMMENTS')

See this help document for more information.

Message 9 of 11

gasevsm
Alumni
Alumni

Hi Tim,

 

My recommendation is to use

 

 

item.performWorkflowTransitionByCustomID('CUSTOM_ID', 'COMMENTS');

That way you may reuse the script in production, staging, dev tenants as needed. Simply create a custom ID i.e. user defined alias in the WF Editor for that transition; All sites would use it without worry of constantly updating transition IDs as you update and copy the script around.

 

 

The example suggested would work surely, but I'm wasn't sure this is what you had wanted originally. By  all means use it, so long as there is awareness that this necessitates another WF state and a transition to it. Possibly semantics, but this isn't quite an action script directly calling validation script and acting on it's outcome. Rather, both the condition script and then the validation scripts of the next WFTransition (one called via script function) will run independently of current transition's transaction, which would complete once action script runs through to the end.

 

HTH,


Martin Gasevski | Fusion 360 Team Product Manager
0 Likes
Message 10 of 11

Anonymous
Not applicable

Currently, I have the following workflow:

 

Workflow.JPG

 

This may be somewhat simplistic, but I'm assuming that if it gets more complicated than that I will be able to get information about the current workflow state and which transitions are available to it within the script (via such things as item.workflowActions and item.workflowItems) and make a decision from that.

 

At this point, I don't have the need to pass any information to the validation script, so that shouldn't be a problem.  I don't forsee that being a problem in the future either.  All the information is in PLM, the scripts just manipulate what's already there.

0 Likes
Message 11 of 11

Anonymous
Not applicable
Accepted solution

Actually, upon further investigation, it seems that I can't do what I thought I could with that method.  This is because the workflow editor requires that custom IDs be unique (which is reasonable), and the scripting tools do not provide access to the current state of the item (I thought this was provided by newStep preset parameter, but as it turns out, that parameter is only set in a validation script).  The result is that the action script doesn't know where it is in the workflow and therefore cannot know which transition to perform.

 

In light of that, I'm not exactly sure why the method exists in the first place.  The only time it would work is if the transition ID were hard coded into the script and the script were only run when the item was in a particular state.  If it is run when it is in any other state, an error is produced.  The script has no way of confirming that the user is running it when the item is in the correct state, and there is no way to make the action script available in one state.  Why provide access to methods without also providing means of getting the information those methods need to run in the first place?