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

Question

Question

Problem adding field not contained in Template

asked on January 3, 2019

I am trying to add an additional field not contained in a template using SDK 10.2.
The FieldValueCollection.Add() method's isIndependent parameter seems to be ignored.
Even if I specify true for this parameter, I still receive the following error:
"Could not find the field specified, or the field is not part of the specified template. [9016]"

Code example:

            using (DocumentInfo docInfo = new DocumentInfo(laserFicheSession)) {
                docInfo.Create(lfDocumentName, laserFicheVolume, EntryNameOption.AutoRename);

                FieldValueCollection fieldValues = new FieldValueCollection();
                fieldValues.Add("First Name", lfTemplateFields.FirstName); // template field
                fieldValues.Add("Last Name", lfTemplateFields.LastName); // template field
                if (!String.IsNullOrEmpty(lfTemplateFields.TransactionNumber)) {

                    // NOT template field
                    fieldValues.Add("Transaction Number", lfTemplateFields.TransactionNumber, true);
                }
                docInfo.SetFieldValues(fieldValues);
                docInfo.SetTemplate("Student");
                docInfo.Save(); // error on this line if NOT template field is present
            }

Thanks for any insights,
Matthew

0 0

Answer

SELECTED ANSWER
replied on January 3, 2019 Show version history

The first thing I would check is what happens when you try to update the field without applying the template. I just tested a stripped down version of this code and everything works correctly as long as the field name exists.

            using(DocumentInfo docInfo = (DocumentInfo)this.BoundEntryInfo){
                FieldValueCollection fieldValues = docInfo.GetFieldValues();

                fieldValues.Add("Type","Test",true);

                docInfo.SetFieldValues(fieldValues);
                docInfo.SetTemplate("General");
                docInfo.Save();
            }

If the field name provided doesn't match and it can't find the field, then you'll get that error when it tries to save, so it might not be related to the template at all.

 

You might also want to set the template and fields at the same time using the overloads instead of setting them in separate actions.

// Set Template, Set Values, and Keep Old Values
docInfo.SetTemplate("Test",fieldValues,true);

 

0 0
replied on January 3, 2019

Jason: This text of yours put me on to the right track:

If the field name provided doesn't match and it can't find the field, then you'll get that error when it tries to save, so it might not be related to the template at all.

I had not defined the field in Laserfiche Administration Console.  Once I did that, it worked fine.   I was thinking I could add a dynamic field "on the fly" and it didn't occur to me that I had to define it ahead of time.

Thank you!

 

0 0

Replies

replied on January 3, 2019 Show version history

You may also try

fieldValues.Item("Transaction Number") = lfTemplateFields.TransactionNumber;

The documentation for FieldValueCollection.Item(FieldName As String) states:

Setting a field will add its value to the current collection if the field does not already exist in the collection. If the field value already exists, the value will be overwritten.

 Another thing to check is the field type and the object type you are trying to pass it.  You may need to cast to the correct type if they do not match.  For instance, you cannot pass an int object to a date field.

0 0
replied on January 3, 2019

This works for me using the 10.2 SDK and LFS 10.2. Can you verify that the field names are correct and that the fields exist in the repository?  Try doing Field.GetFieldInfo for the three fields, and call FieldValueCollection.Add with FieldInfo.Name, this will verify that there are no typos in the field names and that they exist in the repository.

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

Sign in to reply to this post.