コミュニティ

FC12 - Delete line item by script

I have some document where I always need to delete some item lines. In this example it's just if FC reads an article number called 321469. This script was made in the stadard EU Invoice Project as an automated batch stage after Recognition. 

My problem is if I want to delete multiple lines. The number of lines has changed (obviously) and I've can't figure out if I should loop through the whole item lines over and over again depending on the number of lines that I want to delete.

All of the commented out code is just to create a text file with the result. Should not be used in production.

I've created this code based on some examples and it shows all field values (including item lines) - I've can't post the entire code, so please see the text file

using System.Collections.Generic;

using System;

string sDeleteLine;

 

    int [] field_columns = new int[9] {0, 3, 7, 8, 12, 16, 21, 22, 24};

 

    foreach(IDocument doc in Batch.Documents) {

        foreach(IField section in doc.Sections) {

            foreach(IField field in section.Children) {

                

                if (field.Name == "LineItems") {

                sDeleteLine = "";

                   for (int l = 0; l < field.Items.Count; l++)

                   {

                       for (int i = 0; i < field_columns.Length; i++)

                       {

works without any problems.

                           if (field.Items[l].Children[field_columns[i]].Name == "ArticleNumber" && field.Items[l].Children[field_columns[i]].Text == "321469")

                               sDeleteLine = "Delete";

                        

                            // -------------------------

                            // my problem is here! deleting line no. 2 (or line 3, 4, 5 and so on - BUT NOT ALL)

                           if (field.Items[l].Children[field_columns[i]].Name == "ArticleNumber" && field.Items[l].Children[field_columns[i]].Text == "325ISI")

                           {

                               sDeleteLine = "Delete";

                               i--;

                           }

                            // -------------------------                        

                       }

                       

                       if (sDeleteLine == "Delete")

                       {

                           field.Items.Delete(l);   

                           sDeleteLine = "";

                       }

                    }

                }

            }

        }

    }

この記事は役に立ちましたか?

0人中0人がこの記事が役に立ったと言っています

コメント

1件のコメント

  • Avatar
    Permanently deleted user

    Hello,

    Sorry for delay in answering. Is the issue still actual? We have not understood the entire problem based on the post text and available code snippet, so if the problem still needs to be resolved, please specify what result you expect to get by using your code and what you actually get.
    0

サインインしてコメントを残してください。