Page 1 of 1

SignaturePad works intermittently

Posted: Wed Aug 11, 2021 12:54 pm
by k2R400
Hello,

I have a SignaturPad and a button with the code below:

Code: Select all

const obj = JSON.parse('{ "signaturePadId": "SignaturePad", "dir": "/tmp", "imageType": "image/png", "fileName": "SaMQDE5CfdfvfJC6rkqf.png ", "overwrite": true }');
pui.uploadSignature(obj);
pui.click();
The file is saved in /tmp but only every other time ...
The RPGLE program that calls this screen has a simple EXFMT and ends with * INLR = * on
One time it works, then a second time no, no file is generated in the IFS, any idea why?

Re: SignaturePad works intermittently

Posted: Wed Aug 11, 2021 1:58 pm
by Scott Klement
I feel like there may be a timing issue, here.

You run pui.uploadSignature() -- which causes an upload to run in the background. How long that upload takes will depend on the size of the signature, the speed of the network, how fast the server is able to respond, and several other things, so there's no easy way to tell how long it'll take.

Meanwhile, you run pui.click(). This will submit all of the screen data back to your RPG program, causing it to do processing, etc. When its done, it will send another screen, which will destroy the current screen (including the upload running in the background) and draw a new one.

So, it seems to me that doing a pui.uploadSignature() followed immediately by pui.click() would cause a "timing problem". Sometimes it may work, sometimes it may not. It'd depend on which network request finishes first.

Re: SignaturePad works intermittently

Posted: Wed Aug 11, 2021 3:20 pm
by k2R400
Thanks Scott.
So what is the solution?
Maybe using the handler?

Re: SignaturePad works intermittently

Posted: Fri Aug 13, 2021 7:17 pm
by Scott Klement
Right, do the pui.click() in the handler so you know it has completed.

Re: SignaturePad works intermittently

Posted: Thu Aug 19, 2021 1:54 am
by k2R400
Thanks Scott.
But in my example at the beginning of this post, with a JSON.PARSE, how to code the call to the handler.
must admit that I have a little trouble with JS

TY

Re: SignaturePad works intermittently

Posted: Thu Aug 19, 2021 3:53 am
by Scott Klement
Can you explain why you are doing the JSON.parse? since the code you are parsing is hard-coded right there on the screen, it seems to me that you are just adding extra work for yourself vs. just coding the js object. Why use json parse?

But, even so, you could just add the handler to the obj after the parse, so I don't really see the problem.

1. change from 'const' to 'var' so that it is not constant, i.e. you can make changes to it.
2. after the parse, do obj.handler = function() { pui.click() }

Re: SignaturePad works intermittently

Posted: Fri Aug 20, 2021 3:58 am
by k2R400
Thanks a lot !