This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A duplicate property value [PropertyName] was encountered error

Hello everyone!

Today I stumbled upon an odd error. Couldn't really figured out what's wrong. So I have a VAF running in my vault during Before Create New Object Finalize event handler.

The script meant to set properties before the object is created. The first run after deployment is smooth sailing. However, on the second object creation and so on, it threw an error "A duplicate property value [PropertyName] was encountered". I double checked the variable returns only one value not multiple. Below is the snippet on how I set the properties after getting the data from the searching. Is this a known issue or a bug? Or perhaps I should add something to the script?

var oResults = env.Vault.ObjectSearchOperations.SearchForObjectsByCondition(oSc, true);
int theobjID = 0;               

                if (oResults.Count > 0)
                {
                    
                    foreach (ObjectVersion routing in oResults)
                    {
                        if (routing.ObjVer.Type == 101) 
                        {
                            theobjID = routing.ObjVer.ID;

                            break;
                        }
                        break; //to make it run only once 
                    }
                }
                

                var Remarks = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Remarks");
                aPropVal.PropertyDef = Remarks;
                aPropVal.TypedValue.SetValue(MFDataType.MFDatatypeMultiLineText, fData[4]);
                aPropVals.Add(-1, aPropVal);

                var TheGroup = env.Vault.PropertyDefOperations.GetPropertyDefIDByAlias("BP.PD.Groups");
                aPropVal.PropertyDef = TheGroup;
                aPropVal.TypedValue.SetValue(MFDataType.MFDatatypeLookup, theobjID);
                aPropVals.Add(-1, aPropVal);

                env.Vault.ObjectPropertyOperations.SetProperties(env.ObjVer, aPropVals);


Thank you in advance!

Parents
  • Might the properties collection already contain a value for one of these properties? How is it populated? 

  • I have solved the issue. The PropertyValues must be inside the function. Placing it as a public variable will trigger the error apparently.

  • You should be very careful with any public members. In general you should reduce the scope of everything to the minimum possible; in this case within the method.

    What's happening here is that the first object version populates an entry in the collection, then the second object version adds another for the same property definition. As a result there's then two entries in the collection.

    My rule of thumb: never use public members on your vault application class, and use other long-lived items (e.g. static) sparingly and only if you understand the consequence of doing so.

Reply
  • You should be very careful with any public members. In general you should reduce the scope of everything to the minimum possible; in this case within the method.

    What's happening here is that the first object version populates an entry in the collection, then the second object version adds another for the same property definition. As a result there's then two entries in the collection.

    My rule of thumb: never use public members on your vault application class, and use other long-lived items (e.g. static) sparingly and only if you understand the consequence of doing so.

Children