Can I update a field w/JS and reference in RPG

Use this board to ask questions or have discussions with other Rich Displays users.
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Can I update a field w/JS and reference in RPG

Post by ppbedz »

Does anyone know if I can update a bound program field with javascript and access the value in an rpg program. I am using the following to update a program field with the grid row updated by a user. The value (4) appears on the screen, but when the program references it, it is 0. This is the js code:
applyProperty("T_RowNum", "value", RowNum);
applyProperty("T_RowNum", "field type", "output field");

In the enclosed example, the user clicks the decline button, a function turns the button red and sets the program field to 4. The program sees the value as 0, instead of 4.
Attachments
Capture.PNG
Capture.PNG (71.86 KiB) Viewed 1037 times
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Can I update a field w/JS and reference in RPG

Post by Scott Klement »

Output fields are output-only, their data is never sent back to the host. If you want the data sent back, you'll need to change it to a textbox.

Also, you should never use applyProperty() for the value property. The value property is a special case that should be changed using the pui.set() API (or changeElementValue -- which is the same thing as pui.set)
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Re: Can I update a field w/JS and reference in RPG

Post by ppbedz »

Thank you Scott,

I changed my code as suggested and the value is being retained. However, I am noticing that when control returns to the program the colors on my buttons disappear. I have functions that turn the buttons green/red when they are clicked. I am going to enclose my functions along with screen shots. (Looks like my screen shots are in reverse order)

Patti
Attachments
Capture2.PNG
Capture2.PNG (64.2 KiB) Viewed 1032 times
jsonsample.txt
(2.42 KiB) Downloaded 143 times
Capture.PNG
Capture.PNG (63.24 KiB) Viewed 1032 times
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Can I update a field w/JS and reference in RPG

Post by Scott Klement »

Whenever you send control back to the RPG program and it does a new EXFMT, the entire display is re-drawn.

So if you're running custom JavaScript that changes the display, you'll need to re-run that code and re-do your changes after an EXFMT.
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Re: Can I update a field w/JS and reference in RPG

Post by ppbedz »

got it... thank you!!!
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Re: Can I update a field w/JS and reference in RPG-?

Post by ppbedz »

Scott,

Regarding my buttons in the grid, once I click the button and the JS turns it the appropriate color, if I click again (without returning to the program), it does not go back into the function. I assume because it thinks the onclick has already been processed. Is there a way to turn off/reset the onclick at the end of my function so that if the user clicks it again, it will perform the function again? My scenario would be the user accidentally clicks the wrong button and clicks it again to "de-select" it. I tried the following, but it did not work.

getObj("B_Accept" + "." + row).clicked = false;

Thank you,
Patti
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Can I update a field w/JS and reference in RPG

Post by Scott Klement »

Patti, the onclick event runs every time you click. It does not have any concept of "already processed" or anything like that, it just always runs the code when you click it.
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Re: Can I update a field w/JS and reference in RPG

Post by ppbedz »

Scott, That's interesting because I have an alert at the beginning of the function and it does not display when I click it again. That is what made me think the function was not being executed on the second click.

function clkAccBtn(row) {


var BtnAccColor = getObj("B_Accept" + "." + row).style.backgroundColor;

var AccColor = "#32CD32";
var DecColor = "#FF0000";
var DefColor = "transparent";
var AccBtn;
var DecBtn;
var AccChk = "0";
var DecChk = "0";
var RowNum = 0;

alert("accept button is " + BtnAccColor);

// Set the accept/decline buttons and corresponding check box



if (BtnAccColor == DefColor)
{

AccBtn = AccColor;
AccChk = "1";
DecBtn = DefColor;
}
else
{
AccBtn = DefColor;
}


getObj("OOgrid").grid.setDataValue(row, "S1ACCEPTED", AccChk);
getObj("OOgrid").grid.setDataValue(row, "S1DECLINED", DecChk);
applyProperty("B_Accept" + "." + row, "background color", AccBtn) ;
applyProperty("B_Accept" + "." + row, "field type", "button");
applyProperty("B_Decline" + "." + row, "background color", DecBtn) ;
applyProperty("B_Decline" + "." + row, "field type", "button");
pui.set("T_RowNum", RowNum);
getObj("B_Accept" + "." + row).clicked = false;

}
ppbedz
Experienced User
Posts: 147
Joined: Tue Jun 17, 2014 4:00 pm
First Name: Patti
Last Name: Bednarz
Company Name: McGard
State / Province: New York
Country: United States
Contact:

Re: Can I update a field w/JS and reference in RPG

Post by ppbedz »

Scott,

The function is only executed again if I return control to the rpg program first.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Can I update a field w/JS and reference in RPG

Post by Scott Klement »

The only time I've run into stuff like that is if some JavaScript code gets stuck in a loop (or similar.) Since there's already JS code running and it hasn't finished (because it's stuck) subsequent code does not run.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests