Question
How to modify table content and add table rows from the script rule?
Answer
- In order to modify a table cell content, please create a script rule on the section (top) level:
- You would only need your table column to be specified in the rule settings (column alias is AlternativesCustomerName):
- Here is the rule text:
Context.Field("AlternativesCustomerName").Items[0].Text = "test";
- In order to add a table row, please use the event triggered After document rules are checked. Adding a new row is not available from the field rule script:
- Here is the script text:
// if no rows, then add one
if (Document.Field("Commercial Invoice\\Alternatives").Items.Count < 1) {
Document.Field("Commercial Invoice\\Alternatives").Items.AddNew(0);
}
Note: you may use any text field with a “flag” content instead of checking Document.Field("Commercial Invoice\\Alternatives").Items.Count < 1.
Please be careful to avoid endless cycle, because this event is triggered again and again: if it adds new rows to the table => table is changes => rules are checked again => “After document rules are checked” is triggered.
Comments
1 comment
Sameera
using Document.Field gives me the error "The name Document does not exist in the current Context". How can I resolve this. How do I pass the IDocument Argument ?
Please sign in to leave a comment.