Using JavaScript in Expressions (row-update)

I may be trying to do something that just isn’t possible…

I have a Data View that is populated during a GetByID_OnSuccess
after event. I use this Data View to populate a custom grid on a new tab on their Job Entry form to show DMRs tied to the job.

Besides showing the data, they want a flag to note if there are open DMRs. My hope was, like I did in the E10 custom code, I could re-use this data view, and simply get a count of records in it where it’s Calculated_IsOpenDMR column has values of ‘Y’.

I tried the below expressions and I listed the errors.

%OpenDMRsForJobDV.filter(m => m.Calculated_IsOpenDMR == 'Y').length%
- SyntaxError: Unexpected token '%'

I got this idea using the post: Get count of a DataView rows in a Grid in Application Studio - Kinetic ERP - Epicor User Help Forum

I then found the below posts:
String replace (or other string functions) in application studio - Kinetic ERP - Epicor User Help Forum
Row-update expression formats? - Kinetic ERP - Epicor User Help Forum

And tried the below to no avail…

"{OpenDMRsForJobDV}".filter(m => m.Calculated_IsOpenDMR == 'Y').length
- function body "{OpenDMRsForJobDV}".filter(m => m.Calculated_IsOpenDMR == 'Y').length thrown exception TypeError: "{OpenDMRsForJobDV}".filter is not a function

"{OpenDMRsForJobDV}".data.filter(m => m.Calculated_IsOpenDMR == 'Y').length
- function body "{OpenDMRsForJobDV}".data.filter(m => m.Calculated_IsOpenDMR == 'Y').length thrown exception TypeError: Cannot read properties of undefined (reading 'filter')

I figured worst case I could build a function library to check the values.
– UPDATE: I ended up creating two Data Views, one for all records and the other that only contains the records where IsOpenDMR = ‘Y’. Not ideal as I hit the BAQ twice, but it works. Still would love any thoughts on the JavaScript approach. Thanks!

Any thoughts would be greatly appreciated, thank you!!

4 Likes

I believe the syntax should be like this

#_ /*Put your code here*/ _#
2 Likes

can we us #_ _# in any expression in the application studios widgets, or only at row-update? and also what else we can do with JS there?
Thanks

For dev tools, I used javascript to put a doggie icon in the lower right corner of the screen, and create a nifty animation when switching pages within the dashboard. My solution .zip is posted there and you can see the row-update expressions used inside.

Generally speaking, if it says “expression” in app studio, you can use javascript there. If it says “value” it will be interpreted literally instead of passed through Eval(). There are one or two exceptions where you can use javascript without #_ _#


ezgif-78959b9a21389d8c

1 Like

.filter is a method of array in javascript. to get the .data array of a dataview you can do trans.dataView(‘yourDataViewName’).data

trans.dataView('OpenDMRsForJobDV').data.filter(m => m.Calculated_IsOpenDMR == 'Y').length

Be aware this array is only what’s in the local dataview which is affected (in an inconsistent manner) by the various client-side vs server-side filter and paging methods .