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
Comments
5 comments
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.
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.
double newTotal = 0;
{
newTotal = currentTotal * -1;
Context.Field("Total").Text = newTotal.ToString();
}
{
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();
}
}
Document level ??where to input the script? Can you describe more clearly
yong_lee7015, open the "Document Definition Properties" and go to the Rules tab. This is "document level". You can apply rules at the document, section, group, or field level. There is a difference.
Thank you very much , buddy. It works.
Please sign in to leave a comment.