Community

How to copy field's text value in repeating group

Hi Team,

Please, i have repeating group (Group Name : Table) with 9 fields ( Field1, Field2( is CarID), .. Field9)

I need to copy the text value of Field2 of instance 1 to instance 2 (if instance 2 is empty)

I created script rule at level of table (owned by table) to check if instance2 in the group is empty then get value from instance1. but im getting error during run time 

"A rule owned by repeatable group or its' child should change only child field of this group"

Here is the code (VB Script):

dim i
i = Me.Field("Table").Items.Item(1).Field("CarID").items.Count
for i = 0 to i-1
if i>0 then
if (Me.Field("Table").Items.Item(1).Field("CarID").Items.Item(i).Text ="") AND  (Me.Field("Table").Items.Item(1).Field("CarID").Items.Item(i-1).Text<>"") then


Me.Field("Table").Items.Item(1).Field("CarID").Items.Item(i).Text = Me.Field("Table").Items.Item(1).Field("CarID").Items.Item(i-1).Text
end if
end if

next

0

Comments

2 comments

  • Avatar
    Zina Al-Tukmachi

    Hi,

    As reference to others in case they need same rule, I found the solution, the code should be place at higher level than my repeating group , in my case the document level & the code was as easy as:

    dim i
    i=me.Field("Car_ID").Items.Count
    for i= 0 to i-1
    if i>0 then
    if me.Field("Car_ID").Items.Item(i).Text="" and me.Field("Car_ID").Items.Item(i-1).Text<>"" and me.Field("Car_ID").Items.Item(i-1).IsVerified= true then
    me.Field("Car_ID").Items.Item(i).Text= me.Field("Car_ID").Items.Item(i-1).Text
    me.Field("Car_ID").Items.Item(i).IsVerified=true

    end if
    end if
    next

     

    Thanks & Regards,

    Zina.

    0
  • Avatar
    Adrian Enders

    Here is a C# sample I have used before. "LineItems" is the Repeating Group. This script is reversing the sign of all rows for Quantity and Price, by multiplying by -1.

     

    using System;
     
    double currentTotal = 0;
    double newTotal = 0;
     
    if (Double.TryParse(Context.Field("Total").Text, out currentTotal))
    {​
        newTotal  = currentTotal * -1;
        Context.Field("Total").Text = newTotal.ToString();
    }​
     
    for (int i = 0; i < Context.Field("LineItems").Items.Count; i++)
    {​
        double currentQty = 0;
        double newQty = 0;
        if( Double.TryParse(Context.Field("Quantity").Items[i].Text, out currentQty) )
        {​
            newQty = currentQty * -1;
            Context.Field("Quantity").Items[i].Text = newQty.ToString();
        }​
        
        double currentNetTo = 0;
        double newNetTo = 0;
        if( Double.TryParse(Context.Field("TotalPriceNetto").Items[i].Text, out currentNetTo) )
        {​
            newNetTo = currentNetTo * -1;
            Context.Field("TotalPriceNetto").Items[i].Text = newNetTo.ToString();
        }​
        
    }​
    0

Please sign in to leave a comment.