Friday, July 26, 2013

Dynamics GP Run-time Error 1007: Unsafe Operation

Several years ago I developed a customization to display the order weight on the SOP Transaction Entry window.

Earlier this week, the client said that they have been getting an error with the customization in a very specific circumstance.

If they create a Quote with a serialized item, and then transfer that Quote to an Order, they will get the following error:


Run-time error 1007:  Unsafe Operation.  An attempt was made to set a value which violates the application's business logic.

If they use a non-serialized item on the quote, the error does not occur.  And they don't get the error in any other process--only when transferring the Quote with a serialized item to an Order.

This is odd for many reasons, but rather than try and figure out why it occurs, we are lucky enough to have KB article 856199 that describes the problem and offers a solution.

In my original code, I was assigning the order weight value to the custom field on the SOP Transaction Entry form:

TotalOrderWeight.Value = FormatNumber(rst.Fields("ORDERWEIGHT").Value, 2, vbTrue, vbFalse)

Well, it seems that this can trigger the error for some reason.  The workaround is to use the Focus method to assign the value, something I had never used before.

TotalOrderWeight.Focus (FormatNumber(rst.Fields("ORDERWEIGHT").Value, 2, vbTrue, vbFalse))

Sure enough, when I used the Focus method, the error went away.  Go figure.

Written By Steve Endow

Steve Endow is a Dynamics GP Certified Trainer and Dynamics GP Certified IT Professional in Los Angeles.  He is also the owner of Precipio Services, which provides Dynamics GP integrations, customizations, and automation solutions.

You can also find him on Google+ and Twitter



No comments: