That JavaScript will definitely trigger the workflow once - it is no different from the user just clicking save.
A plugin which performs an update (e.g. service.Update(...)
) will also trigger the workflow, that's all intended behavior.
I would start by looking at your plugin, mainly does it have to perform an update call? If you can avoid the double update that should solve your problem.
Did you know that a plugin can make data changes with an update call? If your plugin is registered synchronously and on the pre-event, then any change you make to the target entity object is reflected on the record, this doesn't trigger an additional update - its part of the original message.
For example, if the following code was registered on a pre-event, synchronous plugin the 'new_field'
would be populated with "My new value" and no additional update calls are required.
//get the entity
Entity entity = (Entity)context.InputParameters["Target"];
//set new field
entity["new_field"] = "My new value";
//end of plugin
Failing that it might be worth looking into other options:
- If the plugin is setting the application stage, why is the JavaScript also setting it?
- Is a plugin even required, could it all just go in a workflow?
- May you could look at using a
do not run workflow
field, the field is set by the plugin/JavaScript then when the workflow runs if that field is set it does nothing, but clear the field (not really a recommended option).
- Could the plugin trigger the workflows? Perhaps this could be read from a configuration record?