Application Studio: How to update a field with a rest response field?

Parse from Response Path should be returnObj and Parameter Name should be UserFile.

Do I need to specify actionResult anywhere? I’ve tried different things but actionResult is always undefined.

That used to just work. Looks like you need to specify it now.

Tinkering and trying to get my head around how rest-erp returns data, trying to use the UOM conversion data via UOMClassSvc GetRows:

image

Response looks like:

{
    "returnObj": {
        "UOMClass": [
            {
                "Company": "KNZ",
                "UOMClassID": "VOLUME",
                "Description": "Volume",
                "ClassType": "Volume",
                "BaseUOMCode": "LTR",
                "DefUomCode": "LTR",
                "Active": true,
                "GlobalUOMClass": false,
                "GlobalLock": false,
                "SysRevID": 2139198,
                "SysRowID": "47f8b639-51d4-420a-a7fa-b4b10e206bfa",
                "DefaultUOMClass": false,
                "BitFlag": 0,
                "RowMod": ""
            }
        ],
        "UOMConv": [
            {
                "Company": "KNZ",
                "UOMClassID": "VOLUME",
                "UOMCode": "CUBM",
                "ConvFactor": 1000.0000000,
                "UOMDesc": "Cubic Metre",
                "BaseUOM83": false,
                "UOMCode83": "",
                "Active": true,
                "UOMSymbol": "m^3",
                "AllowDecimals": true,
                "NumOfDec": 2,
                "Rounding": "RND",
                "StdUOM": true,
                "PartSpecific": false,
                "HasBeenUsed": false,
                "ConvOperator": "*",
                "GlobalUOMConv": false,
                "GlobalLock": false,
                "SysRevID": 4603647,
                "SysRowID": "b8148aab-40e8-440f-83be-7335633cf76d",
                "BaseUOM": false,
                "ConvFromUOM": "1 CUBM",
                "ConvToUOM": "= 1000 LTR",
                "DefaultUOM": false,
                "DispBaseUOMCode": "LTR",
                "EnableBaseUOM": true,
                "DispPkgCode": "",
                "DispPkgCodeDesc": "",
                "DispPkgDisplaySeq": 0,
                "DispPkgIsDefault": false,
                "DispPkgDisplayHidden": false,
                "BitFlag": 0,
                "RowMod": ""
            }
        ],
        "ExtensionTables": []
    },
    "parameters": {
        "morePages": false
    }
}

Should you expect to see actionResult in your devtools dataviews afters (ctrl-alt-v that is)? I don’t, but maybe it goes out of scope as soon as the event exits?

I created my own dataview to hold the data and that seems to be working in the meantime:

TYPOS BELOW IN SCREENSHOTS: Parameter Name should be UOMConv not UOMClass to get the conversion factors I’m after. Just noticed that.

image

I originally tried this but it didn’t seem to work, I thought I just needed the path to the data:
image

As far as creating the dataView to receive the data, I’m only interested in a couple of fields, ConvFactor and ConvOperator, so I tried adding just those in the data view page, but seems it populates all fields anyway. Nevermind.

I think @hmwillett showed this yesterday. Let me find it and see if it was the same.

Here it is, if you want to see if it’s the same.

1 Like

You don’t need to do that with this one since the UOMConv table is a collection; the standard rest-erp widget should work.
I’ll take a look when I get to my computer.

Using a DataView

Using actionResult


1 Like

image

This is all correct (minus your need for UOMConv instead of UOMClass). You just needed to look in the “System DataViews” to see the data in Dev Tools; it’s collapsed by default.

image

Parameter name needs to be the table you want data from (UOMConv).
Parse from Response Path will only be returnObj.

1 Like

Aha! That’s where actionResult is lurking

i got that side all working using my dataview, but actionResult seems tidier.

Alas, app studio keeps mashing my events together. On changing and on changed get muddled togther; and looking at the solution json (i sent it to epicare) there’s only one event instead of two and its got bits if both events saved into one. Whichever event i modify last overwrites the other. Went around in circles with this thinking i was going crazy for hours, gave up and went to bed to stare at the ceiling at 2 am.

Is my layer burnt?

That’s… interesting.
Do you leave the first event open while creating the second?
If so, that’s a surefire way for the events to get corrupt; it’s sad to see this is still an issue in 2023.1…

Not necessarily, but your events sure are.

I think I’m gonna make a dashboard so these things can be more easily fixed.

I did. Kinda needed one open as a cheat sheet for the other, as my head wheels get stuck more often these days.

So… if I fix up the remaining event, save it close it, then create the new event, it might be ok you reckon?

For reference, here’s what was left of my onchanging and onchanged events in the solution json:

I think I can simplify it to eliminate the ConvOperator condition, and thus one row update, (using actionResult instead of my view)

  • OnChanging, Update TransView.NV with:
    {Part.NetVolume}{actionResult.ConvOperator}{actionResult.ConvFactor}
  • OnChanged, Update Part.NetVolume with:
    {TransView.NV}/(1.0{actionResult.ConvOperator}{actionResult.ConvFactor})

ie when converting back from base units divide by ( 1 * factor) or (1 / factor), where the * or / in the divisor is ConvOperator. Hopefully doesn’t introduce rounding errors.

and footnote: If we could just type the json in would be sooo much faster than the click fest, which I find very hard to “flow” with, everything takes ages.

That would be… amazing.

Season 9 Nbc GIF by The Office

@hmwillett @klincecum

Its working now!
unit conversion

The volume one uses the new events with REST lookups, and using the divide by (1 operator factor) conversion from base units- this is showing the rounding symbol when converting back, so I’ll revert this to a simple condition and explicit divide and multiply updates

Hanne’s post here helped, shows how to validate the saved json is sensible, and in worst case patch it: Column not showing in Kinetic grid/personaliztion, is in data view - #4 by hmwillett

All it needed was a simple application of a toolchain:

  • Application Studio
  • SQL Server management Studio
  • Notepad++
  • Json Viewer plugin for notepad++

I’m finally coming around to "No-Code " :disguised_face:

For posterity:

		{
			"Id": "CWChangingNetVolumeUOM",
			"Path": "",
			"Value": {
				"trigger": {
					"hook": "columnChanging",
					"type": "DataTable",
					"target": "Part",
					"columns": [
						"NetVolumeUOM"
					]
				},
				"actions": [
					{
						"type": "console-write",
						"value": "Net Volume UOM Changing"
					},
					{
						"type": "rest-erp",
						"param": {
							"requestMethod": "POST",
							"erpRequestMethod": "ErpPostWithDataViewProcessing",
							"methodParameters": [
								{
									"field": "whereClauseUOMClass",
									"value": "UOMClassID='VOLUME'"
								},
								{
									"field": "whereClauseUOMConv",
									"value": "UOMCode='{Part.NetVolumeUOM}'"
								},
								{
									"field": "pageSize",
									"value": 0
								},
								{
									"field": "absolutePage",
									"value": 1
								}
							],
							"svc": "Erp.BO.UOMClassSvc",
							"svcPath": "GetRows",
							"erpRestPostArgs": {
								"processResponse": true,
								"responseParamArgs": [
									{
										"paramName": "UOMConv",
										"viewName": "actionResult",
										"responsePath": "returnObj"
									}
								]
							}
						}
					},
					{
						"type": "row-update",
						"param": [
							{
								"columns": [
									{
										"epBinding": "TransView.NV",
										"expression": "{Part.NetVolume} {actionResult.ConvOperator} {actionResult.ConvFactor}"
									}
								]
							}
						]
					}
				],
				"id": "CWChangingNetVolumeUOM",
				"mode": "U",
				"customizable": true,
				"disable": false
			},
			"Operation": "Add",
			"Index": 588
		},
		{
			"Id": "CWChangedNetVolumeUOM",
			"Path": "",
			"Value": {
				"trigger": {
					"hook": "columnChanged",
					"type": "DataTable",
					"target": "Part",
					"columns": [
						"NetVolumeUOM"
					]
				},
				"actions": [
					{
						"type": "console-write",
						"value": "Net Volume UOM Changed"
					},
					{
						"type": "condition",
						"param": {
							"expression": "{TransView.ConvertUOM} == true",
							"onSuccess": [
								{
									"type": "rest-erp",
									"param": {
										"requestMethod": "POST",
										"erpRequestMethod": "ErpPostWithDataViewProcessing",
										"methodParameters": [
											{
												"field": "whereClauseUOMClass",
												"value": "UOMClassID='VOLUME'"
											},
											{
												"field": "whereClauseUOMConv",
												"value": "UOMCode='{Part.NetVolumeUOM}'"
											},
											{
												"field": "pageSize",
												"value": 0
											},
											{
												"field": "absolutePage",
												"value": 1
											}
										],
										"svc": "Erp.BO.UOMClassSvc",
										"svcPath": "GetRows",
										"erpRestPostArgs": {
											"processResponse": true,
											"responseParamArgs": [
												{
													"paramName": "UOMConv",
													"viewName": "actionResult",
													"responsePath": "returnObj",
													"mergeBehavior": "replace"
												}
											]
										}
									}
								},
								{
									"type": "row-update",
									"param": [
										{
											"columns": [
												{
													"epBinding": "Part.NetVolume",
													"expression": "{TransView.NV} /  (1.0 {actionResult.ConvOperator} {actionResult.ConvFactor})"
												}
											]
										}
									]
								}
							]
						}
					}
				],
				"id": "CWChangedNetVolumeUOM",
				"mode": "U",
				"customizable": true,
				"disable": false
			},
			"Operation": "Add",
			"Index": 589
		}

seth meyers GIF by Late Night with Seth Meyers

Select only, sir!

(Though I was going fix the json and update if necessary, wasn’t needed today, app studio behaved )

Stare Down I See You GIF by Laff

dog hide GIF

i got quite a bit done by ensuring I only edited and saved one event at a time… but think I may have hit a new roadblock: I discovered I needed to handle a REST lookup that might not return a result, ie cgheck for undefined. Added the condition and weid ythings started happening again. Went back to examine what was saved in ICE.XXXDef, SysCharacter03, and found incomplete json.

Maybe this is just an artifact of copying from sql mgmt studio column in the query results, but the character lnegth looks suspiciously like I may have exceeed syscharacter03’s capacity? Yikes.

EDIT Googling it suggests nvarchar(max)can hold 2GB, and exporting to csv and fluffing around I was able to bring in the complete json…phew.

But yes its scarmbling my condition statement resultant actions:

How its supposed to work:

How it incorrectly represents it internally:
image