App Studio update table using Rest Services

Hey y’all, today I am trying to learn how to save a row to a table using rest update services. I am having some trouble since as per usual I thought really hard, did some research, felt like I understood, applied everything and after doing probably everything wrong it isn’t working :smiley:

So to alleviate some pain and hopefully serve as a good example I am asking once again for some assistance from the forum pros :smiling_face_with_sunglasses:. I have a field in the UD02 table that I would like to update when I save a customer part record. The field on the app is pulled from a baq, so my logic was I was hoping to grab the UD02 table from rest services, update a row that I grabbed using the rest service, then use rest services to update the now edited row. Heres what I got so far, I feel like I am on the right track, but I have no idea which row update parameter is specifying which field I am grabbing and where I am passing it to, same issue for the rest services. So, if anyone has a nice example that could demystify it I would be forever grateful!

If anyone needs clarifications on my settings lmk, but I figure they are wrong anyways so it might not matter.

My initial thoughts:

Perhaps change your GetRows to a GetByID as you’re only looking to pull down and update one record.

If you do a GetByID, you have to provide values for all (5) keys in the method parameters so it know which record it is grabbing from the UD02 table.

There are no Request Parameters.

Response Params:

(Your dataview may just be UD02, or something else… whatever you created as the dataview populated by your rest call… mine was named UD02_View… so, make that change as necessary).

I would set the behaviors in between your event actions to “On Success”. That way, you’re not going to try to do a row update unless your GetByID was successful. You’re not going to update the record unless your row update was successful. It may not matter, but that’s my typical approach.

I’m assuming your row-update is writing your edited text field into the UD02 character field.

The Update action settings should look like the below:

Method Param:

Request Parameter > Dataset:

1 Like

What @dcamlin said will probably give you the answer you are looking for,
however, this is one of those cases where the architecture matters more than getting a REST payload right.

Kinetic Web UX is the presentation layer. When you put havy business logic there (calling REST to update a different UD record during a client save event on an un-related BO based on some condition), you end up with:

  • duplicated logic across screens and entry points
  • no guarantee it runs when the record is saved via other paths (DMT, service connect, UBAQ, functions, other UI, integrations)
  • harder debugging and security
  • race conditions if the user saves multiple times or the BAQ data is stale etc…

Best practice is to treat the UI as a client (a presentation layer with light visual business logic), not the system of record for business rules.

Put the update in a server side BPM or directive so it runs for every save, no matter how the save happens and it takes the burden away from the Presnetation layer.

UI modifications should be limited to presentation and user experience concerns, for example:

  • Layout and usability
    • rearranging fields, tabs, grids
    • hiding or showing fields
    • setting labels, help text, tooltips
    • making required fields based on simple user context
  • Client side validation that is purely UX
    • basic format checks (empty, numeric, length, pattern)
    • friendly messages before a save attempt
    • preventing obvious bad input early
  • UI state and workflow
    • enabling or disabling buttons
    • driving visual behavior (colors, warnings, indicators)
    • simple conditional visibility based on other fields on the same screen
  • Lookups and read only data retrieval
    • BAQs for display
    • retrieving reference data to help the user decide
    • calling functions for read operations that do not enforce business rules
  • User initiated actions
    • clicking a button to launch a process
    • running a function that does a well defined task
    • actions where the user is explicitly deciding to do something

But you should try to avoid adding hard business logic, especially if this logic applies across interfaces (Web, Rest, Back end, DMT, front end… etc)

7 Likes

Hmm I got a lot of thinking to do now, as always thank you! I will give both suggestions a try and probably get back some time tomorrow to see if I was able to make it work, hopefully update coming soon, wish me luck!

Good morning! So I tried a few things out going down the route of a BPM, and so far I ended up triggering the UD02 update BO when the customer cross part update BO triggers, then I can set a field.

Only question is now how do I get the field from the BAQ I made on the front end? Passing data from the front end to the back end I guess is where I am a little lost, what is the best practice for that?

That depends, where does the field come from? Is the user entering it?

Yes the user would enter it, I have a field that pulls the existing field on the table using a BAQ, then I would have the user update the field, and after the Erp.BO.CustXPartUpdate BO is called my idea would be to use the BPM to update the UD table but im not sure how to reference the data over in the bpm

So there is a table on every screen (a DataView) called CallContextBPMData this data view / field is sent along with ever server side request so when the UX makes a call to Update it sends along the CallContextBPMData with it.

This is a place where you could put that value and retrieve it at server side. There are other options ofcourse including moving this to a server side function.

2 Likes

great nuanced description of client-side mods, Jose. Thanks!

So wish this was a thing in kinetic. rules and events should be merged and true client-side validation rethought from the ground up.

2 Likes

Okay I have done some work, and I was able to get the data to populate in the callcontextBPMdata field, (I made it fill in a text field, and it does work as intended!) but it doesn’t seem to be saving to the UD02 table after I set the field in the bpm. Here is what I got on the BPM, any idea what I might be doing wrong?

Working portion for those wondering:


and since the update event calls the Erp.Bo.CustXPart BPM, I think I can call this and then the BO method here is calling the UD02 BPM

You need to pull the data out of CallContextBPM and set it to the UD)2 did you do that?

I thought the set field action on the BPM would accomplish that, unless that action doesnt work the way I think it does? Would I have to use a BO method to get the data on the bpm then update the field maybe?

I’m not really following in your screen shot you are invoking a BO method (of some sort) can’t see what, then you are doing a Set… but after you set something you need to run Update.

Sorry I think I got a little confused, let me restart.

I have an event that updates the data of the CallCOntextBPM Character01 field, then calls the UD02.Update Rest service. For the dataset model on the rest service call I copied the Input string from the rest api help page


Then on the BPM side I have the UD02.Update service uses the set field action. I also have an alert now for testing to make sure the CallContextBPMData.Character01 field is successfully pulling to the bpm, which seems to be working.


However the set field action is not updating the table. So I am wondering how I can update the table from the BPM now, would I use the Update Table by Query action maybe?

Your BPM is in a post (after being written to the database) and you are altering the ds object (DataSet in memory) - since this is post, that dataset will never get written to Db.

Move the BPM over to a Pre and it should work as desired. If you need to keep it in a post for some reason, you can make that work too, but ideally put it in a pre.

1 Like

Good catch, I changed it to pre but unfortunately, it’s still not actually editing the data saved on the UD02 field. I am guessing because the ds object is not the same as the actual dataset maybe. Idk just spit balling but then I still wouldn’t know how to update the table.

I’m not too familiar with widgets (i always do C#) - but maybe try adding another message widget after the set field, and display the content of your ds.UD02.Character01, validate that it actually got set.

1 Like

Yeah the alert works but I think set field is wrong, I will try a few different options see if I can make some magic happen
GIF by Ghood Girl Magic

Run a GetByID, get the proper dataset, set the field, and then pass that to update.

1 Like

Thanks for the Tip Kevin, and everyone for the great ideas. I did some soul searching and thinking over the past few days and was able to use kinetic tools to find my inner peace and get this to work!

In the end I ended up not passing the data to a bpm and just used rest services like I originally tried and it seems to be working like a charm, but I can also see how if I am queuing large amounts of data or if data changes on the same UD field occur it can cause issues. (be ready for a large read, gonna document what I did for future epicor learners)


I completed this on a different dashboard, but it is simpler than the first one, so I think this serves as a better example anyways. This dashboard is inventory transfer; we have UD fields stored on UD08 that users need to update when they press the transfer button. I didn’t design this, and from a PM perspective in my opinion this probably doesn’t make a ton of sense, advanced material management is better for this, but I will fix that when I get a quote signed so in the meantime, I am recreating the dashboard in kinetic

First things first, creating the data view using the ice.bo.UD08service call really helped, thanks Kevin. Here are the settings I selected when creating the Data view:


when picking services, I check the BAQ designer to see which service calls the table I am looking for if you aren’t sure. To decide on your method either learn what each rest service does using the rest api, or ask the fellow epicor forum gang for help :smiley:

For the request parameters that depends on how your UDfield is setup, if you are getting the data from a nonUD08 table then your parameters will be different, but match the field up with your existing dashboard’s data view fields that match


if you want to add a filter go ahead, I didnt need one but I did need a save event and delete event so I added those

Next, we need to add the fields that users will interact with. I will use a combo box as an example since it is more complex, but if you got a text field you only have to worry about the epbinding.

Here is the epbinding that references our data view, and I am using the usercodes type reusable combo. Use existing combos and their parameters as examples if you need to make a custom combo box that doesn’t have a reusable combo. In case you don’t know reusable combos are what select the options that are available on a drop down, my options are saved on user defined fields (UDcodes table not UD08) so I use this to get that data and when we run our update it will save the selection to UD08

and I added a filter that references the UDfield in user codes. Set this up in user code maintenance, but I have it setup already

and I rinsed and repeated for about 22 fields, then I was done! Next up is the fun part events

If you recall in our dataview step I made a getbyid event, save, and delete event. The save event gets changed to Update when created but here they are:



For the BO_UD08_GetByID event the rest services and parameters are copied from our dataview, so if you follow along just look at them and they will be filled already. This step was where I failed in my first attempt since in order to use rest service to update the UD08 field I needed to use GetbyID which I didn’t know how to setup, so this helped. I am not sure but maybe using a BAQ to get the data made it impossible to use the update rest service since the ds field was empty due to no get request, but I could be wrong on that so feel free to correct me.

Again, not sure why just updating it in a bpm didn’t work but this did so I’ll take it. Next step we need to load the event, I decided to create a separate event for the load trigger in case I need to reuse the BO_UD08_GetByID, it wasn’t necessary, but this feels like best practice, so I did it.

Here are the parameters for the trigger, if you are selecting a key field as david pointed out in a related post change the target from the current view to keyfields if you are trying to run this after selecting a key field

I need to update the table, so I called the BO_UD08_Update service, the only method parameter needed is the dataset field, and I called it when the user clicks the transfer tool as seen above(this isnt working, ill edit the post tomorrow im done for today, I tested the update with a button click so the rest service is good just need to edit my trigger). You can change this to what makes the most sense for that dashboard, or worst case create an event for each field that triggers when that field is updated, but that was too time consuming in many ways so I went against that.

I noticed the fields I added wouldn’t clear when I pressed the clear button, so I added an event to clear the table. The data set clears, then call the rest service again to try and pull a row without a key selected so it pulls everything. To prevent lag after clear because this rest service is pulling the entire UD08 table, I went into the pageSize method parameter and limited the page size to 1. Pretty messy to be honest but also clever in my opinion so I am proud, but if anyone has a cleaner and faster way let me know.

And finally after this, I was able to edit the fields and load them! For adding new rows you might need UpdateExt? I will investigate this further and update this, and for deleting we already have an event so if needed its there. I will sign off for today but with this for the time being at least I have achieved kinetic zen! Hope this helps

Season 8 Nbc GIF by The Office

2 Likes