You are viewing limited content. For full access, please sign in.

Question

Question

What is the proper way to create multiple fields using the SDK?

SDK
asked on November 21, 2019

I have a delimited file that I'm parsing to create new fields. However, there doesn't appear to be a close or dispose method on the LFTemplateField object. When I call the Create method the second time, I get an error. So I wrote some code where I call into a function to create each field. This seems to work, but doesn't strike me as the correct approach. Here's the code block I'm using to test the concept.

        private void btnCreateFields_Click(object sender, EventArgs e)
        {
            LfApp = new LFApplication();
            LfServ = (LFServer)LfApp.GetServerByName("127.0.0.1");
            LfDB = LfServ.GetDatabaseByName("Repository");
            LfConn = new LFConnection();
            LfConn.UserName = "";
            LfConn.Password = "";
            LfConn.Create(LfDB);

            LFTemplate NewTemp = new LFTemplate();
            NewTemp.Create(LfDB, "CFOAdmin", true);

            for (int i = 1; i < 21; i++)
            {
                CreateField(NewTemp, i);
            }
        }

        private void CreateField(LFTemplate Temp, int count)
        {
            LFTemplateField NewField = new LFTemplateField();

            NewField.Create(LfDB, "Field " + count.ToString(), Field_Type.FIELD_TYPE_STRING, false);
            NewField.Update();
            Temp.AddTemplateField(count, NewField);
            Temp.Update();
        }

 

0 0

Answer

SELECTED ANSWER
replied on November 22, 2019

Can you clarify why you would need to call Create multiple times on a LFTemplateField object? If you want to make multiple fields in a loop, you can move the LFTemplateField object creation inside the loop, like this:

 

    LFTemplate NewTemp = new LFTemplate();
    NewTemp.Create(LfDB, "CFOAdmin", true);

    for (int i = 1; i < 21; i++)
    {
        LFTemplateField NewField = new LFTemplateField();

        NewField.Create(LfDB, "Field " + count.ToString(), Field_Type.FIELD_TYPE_STRING, false);
        Temp.AddTemplateField(count, NewField);
    }

    Temp.Update();

 

1 0

Replies

replied on November 22, 2019

I'm iterating through a file that has information for creating fields. So it's not so much that I want to call Create on the LFTemplateField object multiple times as I just want to be able to loop through a file creating an indeterminate number of fields. So in the actual code I've written the For loop is replaced with a Do While loop where I read each line of a text file, parse the line for the relevant characteristics of the field, create the field, and do it again with the next line until all the fields are created. The question arose because I tried a couple of different approaches before that one and they all produced errors. My worry was that if I created a bunch of LFTemplateField objects without disposing/closing them I would eventually run into some sort of memory error. So far I've been able to create around 200 or so fields in one running of the program without issue using the calling into a function approach. In any case, thank you for the response and providing this alternative suggestion.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.