Kinetic Functions Response Params and

This is a new post, trying to use some of the techniques from these two posts:

This is Kinetic Web, not classic, and we are Hosted

  • I’ve written a function that gathers data and creates a “blob” which is meant for a “.eml” file.

  • This email file is “tweaked” by the user before sending, so for now I need to use the Javascript (hack :wink: ) from @jcgomez and @hmwillett to send it to the client as a downloaded file to open.

  • I have a button, with event that calls my function, and I’m putting a condition after the function to try to get my output blob and pass it to the JScript…but I am having trouble getting the syntax correct

This is my event handler:
image

This is my function signature:
image

At this point I’m only interested in my output param “oBuffer”

My Condition/Param/Expression is set to:
image

The full expression being:
eval ("var byteString = window.atob('{actionView.oBuffer}');let int8Array = new Uint8Array(new ArrayBuffer(byteString.length));for (let i = 0; i < byteString.length; i++) { int8Array[i] = byteString.charCodeAt(i);}let documentBlob = new Blob([int8Array], { type: 'application/pdf' });let fileURL = URL.createObjectURL(documentBlob);console.log(fileURL); window.open(fileURL,'_blank');")

The only change I needed to make was at window.atob('{actionView.oBuffer}')
‘actionView.oBuffer’ is my blob of data (really a string, see error, next)

On my function widget I have not set any of the response parameters (possible issue ?)

Using F12 (and ctrl-alt-8), I see these errors:
image

Note, all my output params are assigned a value of the correct type in the function,
but for some reason oBuffer and oSuccess don’t show one of the errors (in yellow),
also note the “actionResult.returnObj” which is not one of my return params.

For the error in red relating to atob, I’m thinking that’s because oBuffer is one of the params error’d in the yellow section.

I know that’s alot of info, but hopefully many can learn from any help provided.

Thanks for any thoughts

Ignore those. 99.9999% of the time they’re red herrings and show up whether your stuff works or not. @bconner what’s the deal with those? Make them go away. :frowning:

Do you have a view called actionView??
Unless you assign the results of your function response to a view, then the default is actionResult, so yours would read {actionResult.oBuffer}

oh my, as I was proofing my post I saw actionView vs actionResult and just change that, and changed the file type to application/eml in the JS…wow, it’s kind of working now (file is downloaded)

that was a big post to create, it’s kind of like when you can’t find an issue and talk someone thru your code and pow, there it hits you in the face

That’s what my friends are for. :grin:

Ok, so in as much I got a file downloaded, two issues, can I make it have a .eml extension ?

And strangely it’s only 3 bytes vs the correct number is about 1,600 bytes

I’m guessing it has to do with the handing off of the oBuffer parameter still

(I’ve check my oBuffer contents in the response using the Epicor rest api helper)

Oh, and the red error from the JS is gone

Probably? This is a bit outside of my knowledge for JS.
Maybe try changing type: 'application/pdf' to type: 'application/octet-stream' or type: 'message/rfc822' Just throwing some stuff out that I saw on StackOverflow. You’ll have to play with it or someone with more JS knowledge can jump in here.

Not sure on this one, either. :sweat_smile:

You need to go hang here for a bit:

2 Likes

nice, that one worked to make it be an .eml file

I added a console.log('{actionResult.oBuffer}'); at the start of the script, it’s showing null in the console…makes me wonder about the function response parms again

well go fill them in with bs so they aren’t null and find out

Show me the function widget’s response properties in App Studio.

@hmwillett Show me the function widget’s response properties in App Studio.

they are all like this (empty)

image

I have made some guesses on what syntax to put but to no avail

Searching for some documentation on this now

I thought the key was that the condition widget expression’s Javascript was referencing the '{actionResult.oBuffer}' properly, it’s not throwing an error but…it’s not getting the data either

You can find that info from the network tab when your function executes.

ok, sorry…it looks like this:
{"oSuccess":1,"oToAddress":null,"oFromAddress":"scott.janisch@olympusgrp.com","oHtmlBody":null,"oCcAddress":null,"oSubject":null,"oBuffer":null}

so, it is null, not sure why, because if I execute the same in rest helper I get this:

  "oSuccess": 113,
  "oToAddress": "scott.janisch@olympusgrp.com",
  "oFromAddress": "scott.janisch@olympusgrp.com",
  "oHtmlBody": "<html><head><style>p { margin-top: 0 ; margin-bottom: 0 ; }</style></head><body><h1>MKE CHANGE FORM</h1><hr><br><p>Customer Name: TEST, INCC.</p><p>Job: 879940-1-1</p><p>Required Date: 4/14/2023 (release 1)</p><p>Traveler Location: 10: ARTSET</p><br><hr><br><p>Is someone from Olympus aware of or working on this change? &nbsp&nbsp&nbsp Yes / No, If so, who?</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Was change already made or are they waiting for a new traveler? &nbsp&nbsp&nbsp Made / Waiting</p><br><p>Further Approval Needed? Yes / No</p><br><p>Requested Ship Date (if changing): </p><br><p>Change(s):</p><br><p>Additional Information:</p><br><hr><br><p>Email this form to the distro with above information filled out.  </p><br><p>- If the job is in production, SALES must pull traveler and bring to engineering</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Not needed if the only change is moving the date OUT  </p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Contact scheduling to discuss first if moving the date UP</p><br><p>- If the job is OFA, do NOT mark the approval operation complete. </p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Engineering will do so AFTER the change is made. </p></p></body></html>",
  "oCcAddress": "scott.janisch@olympusgrp.com",
  "oSubject": "MKE Change Form",
  "oBuffer": "X-Unsent: 1\r\nX-Sender: scott.janisch@olympusgrp.com\r\nX-Receiver: scott.janisch@olympusgrp.com\r\nX-Receiver: scott.janisch@olympusgrp.com\r\nMIME-Version: 1.0scott.janisch@olympusgrp.com\r\nFrom: scott.janisch@olympusgrp.com\r\nTo: scott.janisch@olympusgrp.com\r\nCc: scott.janisch@olympusgrp.com\r\nDate: 3/31/2023 9:55:09 AM\r\nSubject: MKE Change Form\r\nContent-Type: text/html; charset=us-asciiscott.janisch@olympusgrp.com\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<html><head><style>p { margin-top: 0 ; margin-bottom: 0 ; }</style></head><body><h1>MKE CHANGE FORM</h1><hr><br><p>Customer Name: TEST, INCC.</p><p>Job: 879940-1-1</p><p>Required Date: 4/14/2023 (release 1)</p><p>Traveler Location: 10: ARTSET</p><br><hr><br><p>Is someone from Olympus aware of or working on this change? &nbsp&nbsp&nbsp Yes / No, If so, who?</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Was change already made or are they waiting for a new traveler? &nbsp&nbsp&nbsp Made / Waiting</p><br><p>Further Approval Needed? Yes / No</p><br><p>Requested Ship Date (if changing): </p><br><p>Change(s):</p><br><p>Additional Information:</p><br><hr><br><p>Email this form to the distro with above information filled out.  </p><br><p>- If the job is in production, SALES must pull traveler and bring to engineering</p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Not needed if the only change is moving the date OUT  </p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Contact scheduling to discuss first if moving the date UP</p><br><p>- If the job is OFA, do NOT mark the approval operation complete. </p><p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp- Engineering will do so AFTER the change is made. </p></p></body></html>"
}```

although, now I see that my payload on the network tab is { } so apparently my function isn’t receiving it’s input data properly

can I write to the debug console directly from a function ?

double checking my input/request bindings to the function…

No, but within your function you can write to Ice.Diagnostics.Log.WriteEntry("Tacos!"); which will show in the event viewer on the server.

How are you setting up the method parameters for your function widget in app studio?

Somehow, the method parameters were gone, argh, so now my response looks correct !
I wonder if it was because I was moving steps around, adding/removing steps (not that one tho)

I did not know about the network tab things, thanks

I am now getting an error on the JavaScript hack:
Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

I can try some things to work through that…so close

Ah, ok, but I can use console.log in the JavaScript “hack”…that’s probably what I need now

@josecgomez
using the JavaScript “hack” to download a file, successfully passing my “blob” via
window.atob('{actionResult.oBuffer}') but oBuffer is an output from a function, typed as a String, see any issues there ?

What does oBuffer look like?can you console. log it?

yes…

X-Unsent: 1X-Sender: scott.janisch@olympusgrp.comX-Receiver: scott.janisch@olympusgrp.comX-Receiver: scott.janisch@olympusgrp.comMIME-Version: 1.0scott.janisch@olympusgrp.comFrom: scott.janisch@olympusgrp.comTo: scott.janisch@olympusgrp.comCc: scott.janisch@olympusgrp.comDate: 3/31/2023 2:38:28 PMSubject: MKE Change FormContent-Type: text/html; charset=us-asciiscott.janisch@olympusgrp.comContent-Transfer-Encoding: quoted-printable<html><head><style>p { margin-top: 0 ; margin-bottom: 0 ; }</style></head><body><h1>MKE CHANGE FORM</h1><hr><br><p>Customer Name: TEST, INCC.</p><p>Job: 879940-1-1</p><p>Required Date: 4/14/2023 (release 1)</p><p>Traveler Location: 10: ARTSET</p><br><hr><br><p>Is someone from Olympus aware of or working on this change? (continues)

but a rest response shows there should be \r\n to break the lines up

in a test program, if I take my oBuffer and convert it to a Byte[] the \r\n become 0x0d 0x0a as one would expect and then if I write that Byte[] to a file and name it as .eml, it opens as an email draft

this is the first part of oBuffer in my rest response:

"X-Unsent: 1\r\nX-Sender: scott.janisch@olympusgrp.com\r\nX-Receiver: scott.janisch@olympusgrp.com\r\nX-Receiver: scott.janisch@olympusgrp.com\r\nMIME-Version: 1.0scott.janisch@olympusgrp.com\r\nFrom: scott.janisch@olympusgrp.com\r\nTo: scott.janisch@olympusgrp.com\r\nCc: scott.janisch@olympusgrp.com\r\nDate: 3/31/2023 2:37:39 PM\r\nSubject: MKE Change Form\r\nContent-Type: text/html; charset=us-asciiscott.janisch@olympusgrp.com\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<html><head><style>p { margin-top: 0 ; margin-bottom: 0 ; }</style></head><body><h1>MKE CHANGE FORM</h1><hr><br><p>Customer Name: TEST, INCC.</p><p>Job: 879940-1-1</p><p>Required Date: 4/14/2023 (release 1)</p><p>Traveler Location: 10: ARTSET</p><br><hr><br>

i’ve tried a few different things with the JavaScript, it always wants to strip those out when I convert from my string to the int8Array

I feel like if I could return a byte array from the function, this would work

That’s not base 64 encoded. atob needs a base 64 encoded string. Looks like yours is already decoded. Do return a Byte Array from your function take the File and turn it into a byte array.

byte[] fileBytes = File.ReadAllBytes(strFile);
string base64EncodedString = Convert.ToBase64String(fileBytes);

Return taht.

1 Like