Delete lines from Grid via Form Script

Hi,

I have this simple Form:

When user click on "Get Statement Files" button, I read list of files from IDM according to Formatter Code field (which is defined as Document Type in IDM), and I fill list of files into the Grid.

But when I change Document Type, and again click on "Get Statement Files" button, it is adding new lines, but I need to clear all previous lines first. How can I do it in Form Script?

Here is my Form Script code:

//<Ref>Newtonsoft.Json.dll</Ref>

using System;
using System.Collections.Generic;
using System.Linq;
using Mongoose.IDO.Protocol;
using Mongoose.Scripting;
using Newtonsoft.Json;

namespace Mongoose.FormScripts
{
    public class BCA_SYPF_1 : FormScript
    {
        public void SetBUVar()
        {
            Application.ShowMessage("varBU: " + ThisForm.Variables("varBU").Value);
        }

        public void GetStmFiles()
        {
            if(ThisForm.Variables("varBU").Value == "")
            {
                Application.ShowMessage("BU is not selected", "BPS Warning", wsMessageStyle.wsOKOnly, wsMessageDisplay.wsMsgBox);
            }
            else if(ThisForm.Variables("varFormatterCode").Value == "")
            {
                Application.ShowMessage("Formatter code is not filled", "BPS Warning", wsMessageStyle.wsOKOnly, wsMessageDisplay.wsMsgBox);
            }
            else
            {
                InvokeRequestData IDORequest = new InvokeRequestData();
                IDORequest.IDOName = "IONAPIMethods";
                IDORequest.MethodName = "InvokeIONAPIMethod";
                IDORequest.Parameters.Add("1");
                IDORequest.Parameters.Add("0");
                IDORequest.Parameters.Add(new InvokeParameter("IDM"));
                IDORequest.Parameters.Add(new InvokeParameter("GET"));
                IDORequest.Parameters.Add(new InvokeParameter("/api/items/search?%24query=%2F" + ThisForm.Variables("varFormatterCode").Value + "&%24offset=0&%24limit=1000"));
                IDORequest.Parameters.Add(new InvokeParameter("[{\"Name\":\"Accept\", \"Type\":\"header\", \"Value\":\"application/json\"}]"));
                IDORequest.Parameters.Add(new InvokeParameter(""));
                IDORequest.Parameters.Add(new InvokeParameter(10000));
                IDORequest.Parameters.Add(IDONull.Value);//ResponseCode 8
                IDORequest.Parameters.Add(IDONull.Value);//ResponseContent 9
                IDORequest.Parameters.Add(IDONull.Value);//ResponseHeaders 10
                IDORequest.Parameters.Add(IDONull.Value); //ResponseInfobar 11
                InvokeResponseData response = IDOClient.Invoke(IDORequest);
                if (response.IsReturnValueStdError())
                {
                    Application.ShowMessage("Error: \nResponseCode: " + response.Parameters[8].Value + "\nResponseContent: " + response.Parameters[9].Value +
                        "\nResponseHeaders: " + response.Parameters[10].Value + "\nInfobar " + response.Parameters[11].Value, "ION API Error", wsMessageStyle.wsOKOnly, wsMessageDisplay.wsToast);
                }
                else
                {
                    if (response.Parameters[9].Value.Contains("error"))
                    {
                        RootDocError errDocMsg = JsonConvert.DeserializeObject<RootDocError>(response.Parameters[9].Value);
                        Application.ShowMessage(errDocMsg.error.detail, "ION API Error", wsMessageStyle.wsOKOnly, wsMessageDisplay.wsToast);
                    }
                    else if(response.Parameters[9].Value.Contains("\"item\":"))
                    {
                        RootFileList fileList = JsonConvert.DeserializeObject<RootFileList>(response.Parameters[9].Value);
                        List<Item> sortItem = fileList.items.item.OrderByDescending(o => o.createdTS).ToList();
                        int row = 1;
                        foreach (Item item in sortItem)
                        {
                            ThisForm.PrimaryIDOCollection.New();
                            ThisForm.PrimaryIDOCollection.SetCurrentObjectPropertyPlusModifyRefresh("filename", item.filename);
                            ThisForm.PrimaryIDOCollection.SetCurrentObjectPropertyPlusModifyRefresh("datetime", item.createdTS.ToString("yyyy'-'MM'-'dd' 'HH':'mm':'ss"));
                            ThisForm.PrimaryIDOCollection.SetCurrentObjectPropertyPlusModifyRefresh("downloadUrl", item.resrs.res[0].url);

                            ThisForm.CurrentIDOCollection.SetObjectNew(row, false);
                            ThisForm.CurrentIDOCollection.SetObjectModified(row, false);
                            row++;
                        }
                        ThisForm.PrimaryIDOCollection.SetCurrentObjectModified(false);
                    }
                    else
                    {
                        Application.ShowMessage("No documents for Document Type: " + ThisForm.Variables("varFormatterCode").Value, "ION API Error", wsMessageStyle.wsOKOnly, wsMessageDisplay.wsToast);
                    }
                }
            }
        }

        //****************************
        //* IDM Document Error CLASS *
        //****************************
        public class Error
        {
            public string areaCode { get; set; }
            public string area { get; set; }
            public string code { get; set; }
            public string message { get; set; }
            public string detail { get; set; }
        }

        public class RootDocError
        {
            public Error error { get; set; }
        }

        //**********************
        //* IDM Document CLASS *
        //**********************
        public class Acl
        {
            public string id { get; set; }
            public string name { get; set; }
        }

        public class Attr
        {
            public string name { get; set; }
            public string type { get; set; }
            public string qual { get; set; }
            public string value { get; set; }
        }

        public class Attrs
        {
            public List<Attr> attr { get; set; }
        }

        public class Item
        {
            public string createdBy { get; set; }
            public string createdByName { get; set; }
            public DateTime createdTS { get; set; }
            public string lastChangedBy { get; set; }
            public string lastChangedByName { get; set; }
            public DateTime lastChangedTS { get; set; }
            public string filename { get; set; }
            public string size { get; set; }
            public string pid { get; set; }
            public string pid2 { get; set; }
            public string id { get; set; }
            public string version { get; set; }
            public string drillbackurl { get; set; }
            public string reprItem { get; set; }
            public string displayName { get; set; }
            public string isArchived { get; set; }
            public string entityName { get; set; }
            public Attrs attrs { get; set; }
            public Resrs resrs { get; set; }
            public Acl acl { get; set; }
        }

        public class Items
        {
            public string searchXQuery { get; set; }
            public List<Item> item { get; set; }
        }

        public class Re
        {
            public string name { get; set; }
            public string size { get; set; }
            public string mimetype { get; set; }
            public string filename { get; set; }
            public string url { get; set; }
            public string sha256 { get; set; }
        }

        public class Resrs
        {
            public List<Re> res { get; set; }
        }

        public class RootFileList
        {
            public Items items { get; set; }
        }
    }
}
Parents Reply Children
No Data