Solved

Push sales order line item to user sales order screen and have it appear without refresh?

  • 12 February 2022
  • 11 replies
  • 247 views

Userlevel 6
Badge +5

I would like to push an item to a sales order line in a sales order, and have it appear live while the user is in that sales order. Is there a way to do this with push notifications or some other mechanism, where we can tell the program that there has been an update to a sales order line via the REST api, and then reload that part of the screen to show the update? I know this can be done manually by the user with the little refresh button inside the sales order, but ideally I’d like to have a program that is watching for these changes and can reload that part of the page automatically when the new item is added.

I feel like with enough hackery I can get this to work, but I’m wondering if there is a straightforward way to do it first.

icon

Best answer by rosenjon 29 May 2022, 00:29

View original

11 replies

Userlevel 6
Badge +5

So in reviewing the REST API, it appears that there is no endpoint for the SOLine DAC. That’s interesting. Are there any plans to add this endpoint in the future?

We can touch SOLine through Visual Studio. It would be useful to be able to do some stuff with this as an extension to the SalesOrder endpoint (similar to how CustomerLocations work, etc).

Userlevel 6
Badge +5

Oh man never mind. This is in SalesOrderDetail. It’s been a long day. Scratch this one.

Userlevel 7
Badge

LOL no worries 😁

Userlevel 6
Badge +5

To be clear, I mean scratch the thing about the SOLine and there being no REST endpoint for the line. I still need some help with figuring out if I can remotely push data to a screen and have it appear with a page reload or the user pushing the reload button for the Sales Order details.

Userlevel 4
Badge +1

hi @rosenjon

If your looking for creating a sales order via rest API please find the attached document.  

Hope this helps you. 

Userlevel 7
Badge +11

Hi @rosenjon 

We can achieve this with the REST API endpoint. you need to use the PUT method with SalesOrder entity and update the sales order with new line details

example:
{

    "OrderNbr": {    "value": "SO006654"    },

    "OrderType": {     "value": "SO" },

    "Details": [

        {

            "note": "",

             "InventoryID": {    "value": "AALEGO500" },

            "OrderQty": { "value": "2.0000"  },           

            "ManualPrice": {   "value": true },

            "UnitPrice": { "value": "50.0000"   },

            "ManualDIscount": {  "value": true },

            "DiscountAmount": {  "value": 0  }

        }

    ]

 

}

Userlevel 7
Badge

Hi @rosenjon were you able to resolve this? Thank you!

Userlevel 6
Badge +5

@jinin Is there a way to have the new item appear inside the user’s screen without them refreshing the line items area? That’s what I’m trying to figure out. I have the REST api calls worked out already.

Userlevel 7
Badge +11

Hi @rosenjon 

I think it's not possible to appear the records without refreshing.

Userlevel 6
Badge +5

Just a note here...while I appreciate @jinin ‘s help, that is not the best answer to the question. The REST Api cannot update the user’s view after data has been pushed into the backend via the REST Api.

I am working on a prototype to do this using SignalR and a frontend javascript library to receive the push, but the answer marked “Best Answer” is not an answer to the question and should not be marked as such.

Userlevel 6
Badge +5

Ok, so here is one working answer to this one. Let’s say you want to create an external website that communicates with Acumatica via REST API or Webhook. In my case, I wanted to add Sales Order lines to a Sales Order programmatically.

You push your sales order lines to Acumatica. But in my use case, there are users that have launched an external search screen from the Sales Order screen, and now are presumably wondering why the item they just added to their Sales Order has not appeared in the other screen. Acumatica does not currently have any documented answer to this issue that I have found.

Alas, there is a solution that will work “out of the box”. If you launch the external website from Acumatica using PXRedirectURLException, this launches a new window that has links back to the parent window via the window.opener feature in Javascript.

It’s a little tricky, because native Acumatica is using iFrames to separate the navigation window from the main window inside the native Acumatica site. So targeting that window via window.opener was a little more tricky than usual. However, it can be done with this code below. This says to go get the main iFrame window, and then get its webpage from within the iFrame.

var framedoc = window.opener.document.getElementById("main").contentWindow.document;

We will use this code in the child window that was launched via PXRedirect exception. Then, we can target the refresh button inside of SO301000, for example, with the following code. The simulateMouseEvent function is required for Acumatica to properly register the click on the refresh button (just $(element).click() does not work)...

var simulateMouseEvent = function(element, eventName, coordX, coordY) {
              var returnval = element.dispatchEvent(new MouseEvent(eventName, {
                view: window.opener.document.getElementById("main").contentWindow,
                bubbles: true,
                cancelable: false,
                clientX: coordX,
                clientY: coordY,
                button: 1
              }));
              return returnval;
            };

               var framedoc = window.opener.document.getElementById("main").contentWindow.document;
               var t = framedoc.getElementById('ctl00_phG_tab_t0_grid_at_tlb_ul');
               var x = t.getElementsByClassName("main-Refresh");
               var g = x[0].parentElement.parentElement.parentElement;
               $(g).css( "background-color", "green");
               
               var theButton = x[0];

               var box = theButton.getBoundingClientRect(),
               coordX = box.left + (box.right - box.left) / 2,
               coordY = box.top + (box.bottom - box.top) / 2;
               
               simulateMouseEvent(theButton, "mousedown", coordX, coordY);
               simulateMouseEvent(theButton, "mouseup", coordX, coordY);
               simulateMouseEvent(theButton, 'click', coordX, coordY);

There is even some code in there to turn the background of the refresh button green in the main Acumatica window, as an example of an additional callout that can be made to show that the integration has worked.

Anyway, this one was pretty tricky, so I thought I would share it!

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