Can I update a field w/JS and reference in RPG
-
- 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
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.
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 (71.86 KiB) Viewed 1034 times
-
- 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
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)
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)
-
- 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
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
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 (64.2 KiB) Viewed 1029 times
-
- jsonsample.txt
- (2.42 KiB) Downloaded 143 times
-
- Capture.PNG (63.24 KiB) Viewed 1029 times
-
- 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
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.
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.
-
- 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
got it... thank you!!!
-
- 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-?
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
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
-
- 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
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.
-
- 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
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;
}
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;
}
-
- 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
Scott,
The function is only executed again if I return control to the rpg program first.
The function is only executed again if I return control to the rpg program first.
-
- 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
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.
Who is online
Users browsing this forum: No registered users and 6 guests