This topic is locked
[SOLVED]

Tri-part events

1/9/2025 9:45:32 AM
ASPRunner.NET General questions
G
Garyl author

I am completely mis-understanding Tri-part; no matter what I set in the result in the server event; I never get anything in the client after for result. Looking at the console, it states it cannot read properties of undefined. I don’t care if it is a value, an array, text, etc nothing shows up in Client after.

I have read the documentation, I have looked over the blog, even watch a couple of video's, I have search here in the forum, still don’t have that secret sauce that tells me where I am going wrong, or maybe what I am trying to do just will not work.

In the server event,

string query = MVCFunctions.Concat("select * from patient.tasks where vitallink = '", tsTicks, "'");
dynamic rs = DB.Query(query);
result["record"] = rs.fetchAssoc();

I have data in the result[“record”] and can use it in the server event without an issue.

Client After
Just to see if I get anything here, even if I try to pull something out of result["record"] tell me the same.

console.log("This is what is in the result: " + result["record"]);

Uncaught TypeError: Cannot read properties of undefined (reading 'record')
at pageObj.buttonEventAfter.New_Button11 (button_New_Button11.js?2076_1736280950:53:55)
at Object.success (RunnerAll.js?41974:455:39)
at c (loadfirst.js?41974:1:28327)
at Object.fireWith [as resolveWith] (loadfirst.js?41974:1:29072)
at l (loadfirst.js?41974:1:79901)
at XMLHttpRequest.<anonymous> (loadfirst.js?41974:1:82355)

Any thoughts for guidance would be appreciated.

ASPRunner.Net 10.91

Gary

Sergey Kornilov admin 1/9/2025

You need tomake sure that your query returns data. As far as I can see, your query relies on tsTicks variable that is not defined anywhere.

In either case, you need to use Chrome Developer Tools to see the response from the server code and see what exactly is being passed from Server event to ClientAfter event. Also, printing the actual SQL query from the Server event would be benefitial.

More info:
https://xlinesoft.com/asprunnernet/docs/troubleshooting_custom_buttons.htm

G
Garyl author 1/9/2025

Yes it does return data, and I can use that data in the server event. This is from Dev Tools out of chrome in the response.

select * from patient.tasks where vitallink = 'ts638720182163630057'<br/>{"record":{"Id":103,"PatientId":"638717730519009103","UpdatedBy":"gxxxxxx","TaskTitle":"120","Description":"RPM Vital Review CPT 99457 Provides review of vitals by a qualified clinician","NeedFollowup":null,"FollowupStaffId":"","FollowupTime":"","StaffId":"gxxxxxx","StartTime":"2025-01-19 11:16:56","DueTime":"2025-01-19 11:16:56","CreatedAt":"2025-01-09 11:16:56","FinalOutcome":"","ClosedBy":"","Priority":1,"Status":"2778","Outcome":"","TaskTemplateItemId":null,"TrackedTimeInMinutes":"","DisplayOnSummaryReport":null,"TaskResultId":null,"ActionNeeded":null,"IsUrgent":null,"TaskType":null,"CreatedBy":"gxxxxx","ServiceHistoryId":1,"vitallink":"ts638720182163630057"}}

I defind tsTicks just above that, did not copy it in prior

long ticks = DateTime.Now.Ticks;
var tsTicks = "ts" + ticks.ToString();

I just cannot seem to get it in the ClientAfter Event.

Sergey Kornilov admin 1/9/2025

If the query is correct and data is retrieved and being passed to the ClientAfter event, then it means you are doing something wrong with it in ClientAfter event.

You need to rememer that you are passing an array from Server to ClientAfter event and you need to treat it as an array as opposed to a scalar variable.

G
Garyl author 1/9/2025

Ok so I know that what I am passing did have data, so this evening I took a different approach. I wiped everything out, put in a new custom button, and when clicked I received the Hello World !!!

Then I wiped ever everything in the ClientBefore removed the Parmeter in the Server and just put in quotes Hello World and it worked fine.

I left the ClientAfter the same

var message = result["txt"] + " !!!";
ajax.setMessage(message);

In the Server I added one line of test code at a time:

Test 1

Server
string logFilePath = @"C:\inetpub\prod\temp\checktskupdate.txt";
result["txt"] = "Hello World";

*Compiled
Button pushed
Hello World !!!

Worked as expected

Test 2

Server Code

string logFilePath = @"C:\inetpub\prod\temp\checktskupdate.txt";
DB.SetConnection("master"); //FYI I am setup as a SaaS
result["txt"] = "Hello World";

Compiled
Button pushed
Hello World !!!

Worked as expected

Test 3

Server Code

string logFilePath = @"C:\inetpub\prod\temp\checktskupdate.txt";
DB.SetConnection("master");
string tsticks = "ts638718850720994006";
result["txt"] = "Hello World";

  • Compiled
    Button pushed
    Hello World !!! *

Worked as expected

Test 4

Server Code

string logFilePath = @"C:\inetpub\prod\temp\checktskupdate.txt";
DB.SetConnection("master");
string tsticks = "ts638718850720994006";
string query = MVCFunctions.Concat("select \"Id\" from patient.tasks where vitallink = '",tsticks, "'");
result["txt"] = "Hello World";

Compiled
Button pushed
Hello World !!!

Worked as expected

Test 5

Server Code

string logFilePath = @"C:\inetpub\prod\temp\checktskupdate.txt";
DB.SetConnection("master");
string tsticks = "ts638718850720994006";
string query = MVCFunctions.Concat("select \"Id\" from patient.tasks where vitallink = '",tsticks, "'");
dynamic rs = DB.Query(query);
result["txt"] = "Hello World";

Compiled
Button pushed

FAILED
var message = result["txt"] + " !!!"; Uncaught TypeError: Cannot read properties of undefined (reading 'txt'
button_Vital_Review.js?2121_1736280950:20 Uncaught TypeError: Cannot read properties of undefined (reading 'txt')
at pageObj.buttonEventAfter.Vital_Review (button_Vital_Review.js?2121_1736280950:20:21)
at Object.success (RunnerAll.js?41974:455:39)
at c (loadfirst.js?41974:1:28327)
at Object.fireWith [as resolveWith] (loadfirst.js?41974:1:29072)
at l (loadfirst.js?41974:1:79901)
at XMLHttpRequest.<anonymous> (loadfirst.js?41974:1:82355)

It Seems to be when I use DB.Query that it fails for some reason, NOTE, I never at one time changed what was in result["txt"]. it always had "Hello World" so i know what was being passed to ClientAfter was static.

Gary
Sergey Kornilov admin 1/10/2025

Go back to basics:
https://xlinesoft.com/asprunnernet/docs/troubleshooting_custom_buttons.htm

You need to find where exactly your code breaks and why.

G
Garyl author 1/10/2025

I did, however you throw in the server event DB.Query, DB.Exec, DB, Select, DB, Lookup in that event and it it breaks what ever you try to put in result, or better yet, not even populate it.

If you noticed in my testing, I did not populate result with the result of the query, I kept with Hello World in my trouble shooting. When I put in DB.Query, that is when it broke. The query runs fine, and I can prove I get the correct results expected in the log file, however without even populating result
with the results of the query, leaving it with result["txt"] being Hello World it came up with it being undefined in the ClientAfter.

Again, my flow, create a custom button, run it you get back Hello World !!! now throw a simple query using DB.Query, etc, in the server event, and try to populate result, in my app it breaks.

Gary

Sergey Kornilov admin 1/10/2025

Nobody can possibly tell what is wrong with your code without having access to your project.

I can see in earlier posts that your query was executed and correct data were passed to ClientAfter event. So that part alone wasn't a problem though now you started adding SetConnection() call that wasn't there before.

In either case, you cannot GUESS the correct code. You need to step through the each line of the code and find where it breaks and what is wrong.

G
Garyl author 1/11/2025

Thank you, I figure out a solution for this, Tri-part is working.

Gary