How to modify table content and add table rows from the script rule?

Question

 

How to modify table content and add table rows from the script rule?

 

Answer

  1. In order to modify a table cell content, please create a script rule on the section (top) level:
  2. You would only need your table column to be specified in the rule settings (column alias is  AlternativesCustomerName):
  3. Here is the rule text:
    Context.Field("AlternativesCustomerName").Items[0].Text = "test";
  4. 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:
  5. 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.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.