Skip to main content
Solved

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


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.

Best answer by twagner

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.

View original
Did this topic help you find an answer to your question?

4 replies

davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+3

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.


  • Author
  • Freshman II
  • 4 replies
  • June 28, 2023

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?


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2781 replies
  • July 10, 2023

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


  • Author
  • Freshman II
  • 4 replies
  • Answer
  • July 19, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings