Question

Shopify 21R1 - How to implement core connector Product Data Get/Update resources for new a Graph

  • 11 August 2021
  • 7 replies
  • 84 views

Userlevel 4
Badge

Hello Everyone,

I have a requirement mentioned as below:

  1. I have to create a new graph.
  2. Implement a button on this graph.
  3. On this button click have to Get/Update specific Product data with some additional details.

I am trying to use core connector Product Data Get/Update resources for my new Graph, similar to SPStockItemProcessor graph but is not working. 

Please find below details that I have tried as a part of customization:

  • Created graph - Please find attached ‘Test Graph Code’ document for reference.
  • Created aspx page and defined button - Please find attached ‘aspx Code’ document for reference.
  • Getting object reference error and on debug find out productDataProvider object getting null.

public PXAction<KNSPPLMetaFieldsFilter> CreateStockItem;
        [PXButton()]
        [PXUIField(DisplayName = "Get Product Details")]
        protected virtual IEnumerable createStockItem(PXAdapter adapter)
        {
            ProductData data = productDataProvider.GetByID("6618593099970"); // productDataProvider getting null
            return adapter.Get();
        }

 

Can someone suggest the best possibility way to achieve this please.

Thank you in advance !


7 replies

Userlevel 7
Badge +3

@vivekm Processor is a graph mainly for the customization purpose. It was not designed to be used under the screen. For instance no one calls the Initialize method when you use Processor from the screen.

I suggest you create a new graph as it suppose to be done based on the Acumatica Training guides and than from the button handler create a process and call Initialize and than whatever other methods you need to call from there.

Userlevel 7
Badge +17

Hi Sergey,  I completely agree with you.

In the above case, since it is custom screen and objects like RestDataProvider NOT initialized, hence we are getting the NULL reference error. 

For testing purpose, if I can initialize the RestDataProvider in the constructor just like below, then we can able to make an API call right? Please suggest!
 

	#region Constructor
public override void Initialise(IConnector iconnector, ConnectorOperation operation)
{
base.Initialise(iconnector, operation);

productDataProvider = new ProductRestDataProvider(SPConnector.GetRestClient(GetBindingExt<BCBindingShopify>()));
}
#endregion

 Correct me, If I am wrong.

Userlevel 7
Badge +3

@Naveen B you can call initialize method from the constructor, however I do not recommend you to use Processor as a graph for the screen.

As I said, it would be better to initialize processor from the action.

Userlevel 4
Badge

Thank you @smarenich @Naveen B for the inputs, will implement the suggested approach and verify with that.

Userlevel 4
Badge

Hi @smarenich,


I tried like below but that didn’t worked out. If possible, Can you please share any code sample as how we can initialize ProductRestDataProvider to a new custom Graph in order to call product Get/Update methods.

 

public class Test : PXGraph<Test>
    {
        public PXFilter<KNSPPLMetaFieldsFilter> KNPLFilter;         
        public ProductRestDataProvider prodProvider;

        public PXAction<KNSPPLMetaFieldsFilter> CreateStockItem;
        [PXButton()]
        [PXUIField(DisplayName = "Get Product Details")]
        protected virtual IEnumerable createStockItem(PXAdapter adapter)
        {
            SPStockItemProcessor stkProcessor = PXGraph.CreateInstance<SPStockItemProcessor>();

            //Approach 1: Results object reference error
            ProductRestDataProvider productDataProvider = new ProductRestDataProvider(SPConnector.GetRestClient(stkProcessor.GetBindingExt<BCBindingShopify>()));

            //Approach 2: Results object reference error
            var client = SPConnector.GetRestClient(stkProcessor.GetBindingExt<BCBindingShopify>());            
            prodProvider = new ProductRestDataProvider(client);

            return adapter.Get();
        }       
    }

Userlevel 7
Badge +3

@vivekm you must call Initialise method of the stkProcessor. Since this method is not called, some of the variables are not initialized.

Userlevel 4
Badge

Hi @smarenich 

I tried to call Initialise method using stkProcessor object.

But unable to figure out about iconnector and operation parameters as I am on new custom Graph.

Just for verification tried like below but that too did not helped and resulting ‘object reference error’ as stkProcessor.Connector and stkProcessor.Operation will be null.

SPStockItemProcessor stkProcessor = PXGraph.CreateInstance<SPStockItemProcessor>();
stkProcessor.Initialise(stkProcessor.Connector, stkProcessor.Operation);

 

Can you please suggest the best possible way to do that, and if possible a code sample will be really helpful.

 

 

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