I am adding records to a repeating section.
The idea is a check out.
When I click on the buy button I add a line to the repeating section.
(I check to see if there are any records, because the first time I have an empty row.)
In the check out I want to have rows with unique products.
If I click the same button twice I want to update the quantity not add a new row.
Selwyn helped me with some of the code and some of the code was found on the message board.
I have added 2 sets of code together badly.
I need help to fix it.
Selwyn's code moves the items from the list to a repeating section.
First we check the existing row count, if the row count is 1 then we look to see if there is a value in the row.
If there is a empty row we add the data.
If there is data in the row we add a new row, then add the data.
Subsequently we add rows and data.
In the 'on change event' of the primary key in the repeating section we look to see if there is already a record.
if there is we add one to the quantity and delete the appended row, if not we append a new row.
Everything works.
However if the quantity is changed from 1 to a higher value then the code stops working.
This is where I think my logic has been misunderstood by JavaScript.
I have a video showing what happens.
Here is the JavaScript.
function Buy() {
var flagAddRow = true;
var existingRowCount = {dialog.Object}._getRepeatingSectionRowCount('REPEAT');
if(existingRowCount == 1){
var row1val = {dialog.Object}.getValue('Bagel:1')
if(row1val == '') flagAddRow = false;
var ele = $('{dialog.componentname}.V.R1.REPEAT');
A5.u.element.show(ele,{show: {type: 'blind',duration: 'fast'},hide: {type: 'blind',duration: 1000}} );
}
if(flagAddRow){
{dialog.Object}.addRepeatingSectionRow('REPEAT');
}
var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
var Desc = {dialog.Object}.listGetValue('List1','P_Name');
{dialog.Object}.setValue('Bagel',Bagel );
{dialog.Object}.setValue('Price',Price );
{dialog.Object}.setValue('Description',Desc );
}
// This is the code for onchange
function CheckForDuplicate(ContainerName,FieldName,FieldValue)
{
var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);
CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);
for (var i=1;i<={dialog.Object}._getRepeatingSectionRowCount(ContainerName);i++)
{
var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);
if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {
var Qty = {dialog.object}.getValue('Qty' + ':' + row);
Qty = +Qty + +1
{dialog.object}.setValue('Qty' + ':' + row,Qty);
// I think that the row I want is written and then deleted.
// If I put in an alert I can see the row created but when I click OK it appears to be deleted.
{dialog.Object}.deleteRepeatingSectionRow('REPEAT',-1,true);
}
}
}
My video
http://www.youtube.com/watch?v=5V6BMKLoXg0
Thanks Michael
The idea is a check out.
When I click on the buy button I add a line to the repeating section.
(I check to see if there are any records, because the first time I have an empty row.)
In the check out I want to have rows with unique products.
If I click the same button twice I want to update the quantity not add a new row.
Selwyn helped me with some of the code and some of the code was found on the message board.
I have added 2 sets of code together badly.
I need help to fix it.
Selwyn's code moves the items from the list to a repeating section.
First we check the existing row count, if the row count is 1 then we look to see if there is a value in the row.
If there is a empty row we add the data.
If there is data in the row we add a new row, then add the data.
Subsequently we add rows and data.
In the 'on change event' of the primary key in the repeating section we look to see if there is already a record.
if there is we add one to the quantity and delete the appended row, if not we append a new row.
Everything works.
However if the quantity is changed from 1 to a higher value then the code stops working.
This is where I think my logic has been misunderstood by JavaScript.
I have a video showing what happens.
Here is the JavaScript.
function Buy() {
var flagAddRow = true;
var existingRowCount = {dialog.Object}._getRepeatingSectionRowCount('REPEAT');
if(existingRowCount == 1){
var row1val = {dialog.Object}.getValue('Bagel:1')
if(row1val == '') flagAddRow = false;
var ele = $('{dialog.componentname}.V.R1.REPEAT');
A5.u.element.show(ele,{show: {type: 'blind',duration: 'fast'},hide: {type: 'blind',duration: 1000}} );
}
if(flagAddRow){
{dialog.Object}.addRepeatingSectionRow('REPEAT');
}
var Bagel = {dialog.Object}.listGetValue('List1','Prog_Bagel');
var Price = {dialog.Object}.listGetValue('List1','Prog_Price');
var Desc = {dialog.Object}.listGetValue('List1','P_Name');
{dialog.Object}.setValue('Bagel',Bagel );
{dialog.Object}.setValue('Price',Price );
{dialog.Object}.setValue('Description',Desc );
}
// This is the code for onchange
function CheckForDuplicate(ContainerName,FieldName,FieldValue)
{
var CurrentRow = {dialog.Object}.getRepeatingSectionActiveRow(ContainerName);
CurrentRow = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,CurrentRow);
for (var i=1;i<={dialog.Object}._getRepeatingSectionRowCount(ContainerName);i++)
{
var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow(ContainerName,i);
var rowValue = {dialog.Object}.getValue(FieldName + ':' + row);
if(rowValue==FieldValue && CurrentRow!=row && FieldValue!='') {
var Qty = {dialog.object}.getValue('Qty' + ':' + row);
Qty = +Qty + +1
{dialog.object}.setValue('Qty' + ':' + row,Qty);
// I think that the row I want is written and then deleted.
// If I put in an alert I can see the row created but when I click OK it appears to be deleted.
{dialog.Object}.deleteRepeatingSectionRow('REPEAT',-1,true);
}
}
}
My video
http://www.youtube.com/watch?v=5V6BMKLoXg0
Thanks Michael
Comment