Solved

Is there a way to update parameter of data provider from import/export methods?

  • 22 June 2023
  • 4 replies
  • 135 views

I’m building a custom data provider where I have a parameter that stores a number of documents processed and that needs to be increased every time the export was successfully send the document.

I was thinking to use a parameter for it in the Data Provider but not sure if there’s a way to update it from the export method.

icon

Best answer by twagner 19 July 2023, 22:54

View original

4 replies

Userlevel 5
Badge +1

Hi @twagner 

The data provider parameters are typically used to store static values which are set prior to the execution of a process or report, so directly updating these parameters within the export method may not be straightforward or recommended.

As a workaround, you could consider storing this "number of documents processed" counter in a custom table or DAC field. In this case, every time the export is successful, you could simply increment this counter and then save the updated value in your custom table. Then, in your data provider, you could retrieve the value from this table to use in your queries.

Here is an example of how you could implement this:

  1. Define a custom table: First, you would create a custom table (let's call it ProcessedDocumentCounter) with at least two fields: CounterID and NumberOfDocuments.

  2. Update the counter: In your export method, you would query this table to get the current count, increment it by one, and then update the table with the new value. Here is a rough example:

// Get the current counter
ProcessedDocumentCounter counter = PXSelect<ProcessedDocumentCounter,
Where<ProcessedDocumentCounter.counterID, Equal<Required<ProcessedDocumentCounter.counterID>>>>.Select(this, "DocumentCounter");

// Increment the counter
counter.NumberOfDocuments += 1;

// Update the table
ProcessedDocumentCounter.Update(counter);
  1. Retrieve the counter in your data provider: Finally, you would modify your data provider to retrieve this counter value and use it in your queries. For example:
public class MyDataProvider : IDataProvider
{
public void Initialize(string name, IDictionary parameters)
{
// Retrieve the counter value from the database
using (PXDataRecord record = PXDatabase.SelectSingle<ProcessedDocumentCounter>(
new PXDataField("NumberOfDocuments"),
new PXDataFieldValue("CounterID", "DocumentCounter")))
{
if (record != null)
{
int counterValue = record.GetInt32(0);
// Now use 'counterValue' in your queries...
}
}
}

// Remaining methods...
}

Just remember to handle transaction rollbacks and error scenarios properly to ensure your counter remains accurate even if an export fails.

Thank you for your answer @davidnavasardyan09 ! Would there be an easy way to use a Numbering Sequence in Acumatica for this purpose? Then there’s no need to create custom table and already has a screen built for it for a user to potentially modify it. Are there any helper classes or methods in Acumatica for numbering sequences?

Userlevel 7
Badge

Hi @twagner were you able to find a solution? Thank you!

Hi @Chris Hackett, thanks for checking, looks like I just found it with some help from ChatGPT 😅

I couldn’t find anywhere docs on a helper class for using the Numbering Sequences in Acumatica so I asked ChatGPT and it immediately returned the AutoNumberAttribute class with the GetNextNumber method. Since the AI tool’s information is outdated (last refreshed 2021 September) and the method now requires different/more parameters I had to just do some additional research and experimenting with the function to figure a way to use it. I ended up passing it a “fake”/empty new PXCache<Numbering>(PXGraph.CreateInstance<NumberingMaint>()) as it was a required parameter and in the Export method of a data provider there’s no graph or cache instance, null as ‘data’, the Numbering ID I created (pulled from a data provider parameter) and just DateTime.Now as the dateTime parameter.

 

This seems to be working, after processing it every time I can see the Last Number is incremented to the next number on the Numbering Sequences screen.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved