Expand my Community achievements bar.

SOLVED

ADDITIONAL ROW INSTANCES PROBLEM

Avatar

Level 2

I am creating a form and I have the following issue:

I have a dropdown list and a user can select one of two options. When the user selects one of the options, it populates the values for other dropdown lists that are within a row. I have created a button to add intances of the row and the issue is that the values are only populating on the dropdown list located in the first row and not on the additional rows created when the "Add Row" button is clicked. The PDF form is attached.

I appreciate any help!!

Thank you in advance!
Monti

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I have moved the script from the change event to the exit event:

var vRows = Servicesrow.instanceManager.count;

var vService = this.rawValue;

for (var i = 0; i<vRows; i++)

{

     xfa.resolveNode("Servicesrow[" + i + "]").servicesscript.SetFlooringtypeEntries(vService);

}

The function call now includes the current value of the drop down.
Inside the script object the function is amended:
function SetFlooringtypeEntries(vService)
{
     ...
     ...
     ...
  
   var aFloortype = FlooringtypeFlow[vService];
Lastly the add row button has additional script to call the function for the new row:
var i = servicerequest.Servicesrow.instanceManager.count;
var newInstanceRow = servicerequest.Servicesrow.instanceManager.addInstance(1);
var vService = top.typeofservice.rawValue;
xfa.resolveNode("servicerequest.Servicesrow[" + i + "]").servicesscript.SetFlooringtypeEntries(vService);
This works here. I have also had a look at the dropdown in the second table. This is working (to a degree). It was referring to a script object "listscript" which did not exist.
I hope this gets you going.
Niall

View solution in original post

11 Replies

Avatar

Level 10

Hi,

I think you will need to set up a loop to set the dropdown in each instance of the row. You can calling a script object, so either place this within a loop for the number of rows, or place a loop within script object itself.

Hope that helps,

N.

Avatar

Level 2

Niall,

I am a bit new to Javascript and am not sure how exactly to set up loop like you mentioned on your earlier post. Do you know how to set up the loop script? Or know of an example I look at to get an idea?

Thank you!!

Monti

Avatar

Level 10

Hi,

Here is the script in the change event of the dropdown, which loops through the number of rows and calls the script object for that row:

var vRows = Servicesrow.instanceManager.count;

for (var i = 0; i<vRows; i++)

{

     xfa.resolveNode("Servicesrow[" + i + "]").servicesscript.SetFlooringtypeEntries();

}

Now I also think you need to also call the script when a new row is added (click event of the add button), but the structure is not clear. The script object is based on the change newText of the dropdown, so calling it from the button fails.
It would need some adjustment of the script object.
Good luck,
Niall

Avatar

Level 2

Thank you Niall,

That was very helpful! I really appreciate it. I am still working on figuring out a way to populate the dropdown options without having to change the "change event field" everytime a new row is added. For now I have gotten around that by starting the form with many rows. Again, thank you for all of your help!

Avatar

Level 10

Hi,

I am glad you are making progress. From memory, the script is in the change event of the main dropdown and so the function in the script object is based on the value in "newText". This is the current value of the main dropdown, even before the user exits the dropdown.

I think the follwoing is worth a go with a copy of the form.

In the main dropdown move the script from the change event to the exit event. Then in the function (in the script object) change ".newText" to ".rawValue".

This will make it easier to call the function when a new row is added (as part of the new row script), because it will based on the existing value of the main dropdown.

Hope that helps,

Niall

ps If you run into problems/script falling over - liberal use of the console (Control+J) to see where the script is failing.

Avatar

Level 2

Niall,

Thank you for all of you help.

I looked at the object script but I did not use the ".newText" value. Instead the function goes like this:

function

SetFlooringtypeEntries()

var aFloortype = FlooringtypeFlow[xfa.event.change];

if(aFloortype && aFloortype.length)

{

for(var i=0;i<aFloortype.length;i++)

Servicesrow.Flooringtype.addItem(aFloortype[i][0].toString())

,

middle1.Table1.Row1.AddOns.addItem(aFloortype[i][1].toString());

}

}

I used xfa.event.change. Would I still be able to implement your suggestion?

Regards,

Monticino

Avatar

Correct answer by
Level 10

Hi,

I have moved the script from the change event to the exit event:

var vRows = Servicesrow.instanceManager.count;

var vService = this.rawValue;

for (var i = 0; i<vRows; i++)

{

     xfa.resolveNode("Servicesrow[" + i + "]").servicesscript.SetFlooringtypeEntries(vService);

}

The function call now includes the current value of the drop down.
Inside the script object the function is amended:
function SetFlooringtypeEntries(vService)
{
     ...
     ...
     ...
  
   var aFloortype = FlooringtypeFlow[vService];
Lastly the add row button has additional script to call the function for the new row:
var i = servicerequest.Servicesrow.instanceManager.count;
var newInstanceRow = servicerequest.Servicesrow.instanceManager.addInstance(1);
var vService = top.typeofservice.rawValue;
xfa.resolveNode("servicerequest.Servicesrow[" + i + "]").servicesscript.SetFlooringtypeEntries(vService);
This works here. I have also had a look at the dropdown in the second table. This is working (to a degree). It was referring to a script object "listscript" which did not exist.
I hope this gets you going.
Niall

Avatar

Level 2

Niall,

Thank you very much for all of you help!! Everything works like I wanted it to!!

Do you what code I would use on a "SUBMIT" button to have the form sent to my email? I created a form in microsoft excel and accomplished this by creating a CDO object script in Visual Basic, but I am not sure how that would translate to javascript.

Thank you again!

Regards

Monticino

Avatar

Level 10

You can use the "Email Submit Button" in the Object Library.

Or if you want to get fancier you can script a regular button with Javascript (on the click event):

var oDoc = event.target;
oDoc.mailDoc(
    {
        bUI: true,
        cTo: "email@address.com",
        cCC: "email@address.com",
        cSubject: "Put email subject here.",
        cMsg: "Put message body text here."
    });

Avatar

Level 2

Jono,

Thank you for your suggenstion regarding the submit button. I tried your suggestion but what you suggested requires that the person submitting the form have a desktop mail application (eg. outlook) or save it and then emailing it. I am not sure if it is possible to do this using javascript, but I am looking for a way to have the form submitted without requiring the user to have an email address. I was able to accomplish this in an excel form using visual basic. below is the code I used in visual basic:

Sub CDO_Mail_Workbook()
    Dim wb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim FileExtStr As String
    Dim iMsg As Object
    Dim iConf As Object
        Dim Flds As Variant

    Set wb = ActiveWorkbook

    If Val(Application.Version) >= 12 Then
        If wb.FileFormat = 51 And wb.HasVBProject = True Then
            MsgBox "There is VBA code in this xlsx file, there will be no VBA code in the file you send." & vbNewLine & _
                   "Save the file first as xlsm and then try the macro again.", vbInformation
            Exit Sub
        End If
    End If

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Copy of " & wb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
    FileExtStr = "." & LCase(Right(wb.Name, Len(wb.Name) - InStrRev(wb.Name, ".", , 1)))

    wb.SaveCopyAs TempFilePath & TempFileName & FileExtStr

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

        iConf.Load -1    ' CDO Source Defaults
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.att.yahoo.com"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "cortezflooring@att.net"
            .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With

    With iMsg
        Set .Configuration = iConf
        .to = "cortezflooring@att.net"
        .CC = ""
        .BCC = ""
        .From = """Customer""cortezflooring@att.net"
        .Subject = "Customer Service Request"
        .TextBody = ""
        .AddAttachment TempFilePath & TempFileName & FileExtStr
        .Send
    End With

    Kill TempFilePath & TempFileName & FileExtStr

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

THank you!!

Monticino

Avatar

Level 10

I don't think it's possible unless you are using some of the LiveCycle Server backend products, or submitting to a web service.