Support for Async calls?

Do your methods support Async calls or is already async?

At the moment, I am sometimes getting different validation errors when GetStockingLocation is called by different requests asynchronously for different IDs, see example below:

Avontus.Core.Validation.ValidationException: ‘Validation rule rule://Avontus.Rental.Library.StockingLocation/JobText1Valid/JobText1 failed in property JobText1’

Inner Exception:
ArgumentException: An item with the same key has already been added.

Hello ejjungao. Would you be able to provide some sample code that reproduces this? From what I can tell you’re adding a second item with a name that already exists. If this is the case, I recommend you change the name before adding it. You can also trap that exception and try another name if it fails.

Avontus Dev

This is the line that causes the error:

var site = StockingLocation.GetStockingLocation(item.StockingLocationID, false);

For context, I made a REST API wrapper. When I get 2+ calls to this endpoint, the validation exception pops up, with different reasons depending on the jobsite. It doesn’t happen 100% of the time and I’m not sure why this happens.

Hello ejjungao. Looks like when you’re fetching a stocking location you’re getting a broken rule exception. Can you take a look at the individual stocking location that you’re fetching and look at it in the UI, in Quantify itself. I suspect that you’ll see that the object is invalid. This can happen if the user-defined rules change mid-stream.

@AvontusDev I get that but the exception does not come up again if I resend the request after the exception. Is there anyway to avoid/fix this? I don’t think it’s reasonable to fix a jobsite on the fly as we have a lot of jobsites

Hello Ejjungao. Is the option to require a custom text field enabled on a jobsite? If so, you can turn that off and you won’t get the broken rule anymore. If it’s on I’m assuming that the end-users want it required and in that case you’ll want to check the broken rules before saving, and do something custom (notify end-user, etc.). So, before your save, run this code.

if (job.BrokenRulesCollection.Count > 0)
    foreach (var rule in job.BrokenRulesCollection)
        // Notify and/or Fix things here

@AvontusDev we currently do not have any custom fields set as required:

At the moment I’m just catching these exceptions and notifying the user to request again.

Thanks ejjungao. What about on a specific jobsite that you get the error on? JobText1 is what it looks like is required, can you send a screen grab of that? That’s odd that you’re able to save it after the exception.

@AvontusDev Would just like to clarify that I am only retrieving jobsites to send as JSON payload. No editing and saving are being done through the API. Our users manipulate these jobsites on the Quantify windows application.

Here’s one that I manage to trigger, it looks like it happens randomly. It takes me a few times to rerun the request and trigger the exception. Every occurrence of this exception has been for different jobsites so far.


Value during retrieval:


Snippet of function until exception for reference from this other post:

        public HttpResponseData TrackProduct([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Quantify/branch/{branch}/trackproduct/{productID}")] HttpRequestData req, string productID, string branch)
            _logger.LogInformation("C# HTTP trigger function processed a request.");

            bool success = AvontusPrincipal.Login(user, password);
            if (success)
                TradingPartner branchOffice = TradingPartner.GetTradingPartner(branch);
                var items = StockedProductView.GetStockedProductsByBaseProductID(Product.GetProduct(productID, ProductType.Product).ProductID);
                List<JobSite> retrievedList = new List<JobSite>();

                foreach ( var item in items)
                        // Exception on this line
                        var site = StockingLocation.GetStockingLocation(item.StockingLocationID, false);
// etc...

Thanks for the code here. Would you mind sending a backup of your database to us and we’ll take a look? When you send it along just note that it’s for the API forum. It’s OK if you would like to keep it private, we can continue to debug here as well.

@AvontusDev I unfortunately do not have direct access to wherever this database is as it is being hosted and ran by one of our sister companies. I could ask but it would take some time.

OK, thanks. For a jobsite ID that you’re getting an exception with, can you send a screen grab of the Shipment Properties tab?

@AvontusDev here you go:

I will say right now that our users do not use this tab (usually).

OK, that’s very odd. Sorry, we’re not able to reproduce the issue here. If you could get us a backup we can try that. The error is for sure from jobsite text1 custom field but our setting of the broken rule looks OK. You could try and catch the exception after fetching it and ignoring it (not a very elegant solution at all).

    var site = StockingLocation.GetStockingLocation(item.StockingLocationID, false);
catch (Avontus.Core.Validation.ValidationException ex)
    // Ignore