UserDefinedFieldInfoAgent and CurrentVersion


I'm trying to add a new user defined field using the UserDefinedFieldAgent() against my Dev SuperOffice Online 8.4 sandbox. My code is based on the SuperOffice.DevNet.Online.Provisioning example code, but I'm experience problems with "Wrong version" exceptions when calling the agent.SaveUserDefinedFieldInfo().

Example code

UserDefinedFieldInfo udField = null;

using (var udfAgent = new UserDefinedFieldInfoAgent())
  udField = udfAgent.CreateDefaultUserDefinedFieldInfo();
  udField.Type = UDefType.Contact;
  udField.FieldType = UDefFieldType.ShortText;
  udField.FieldLabel = "My test name";

  if (!string.IsNullOrEmpty(progId))
    udField.ProgId = "MyProgId";

  if (!string.IsNullOrEmpty(tooltip))
    udField.Tooltip = "My tooltip";

  udField = udfAgent.SaveUserDefinedFieldInfo(udField); // << Exception: Wrong version

The solution to get this to work is to add the following line before I call SaveUserDefinedFieldInfo():

udField.Version = <the current version>;

My question is, how can I find the current version of user defined fields? When not using agents I can use UdefHelper.GetCurrentVersion(), but this method is not available when working against the WCF''s.

Thank you.


RE: UserDefinedFieldInfoAgent and CurrentVersion

Your example is not based on the current provisioning library example code.

Use the CreateDefaultUserDefinedFieldInfo(owner, type) overload as seen in the example code.

Disclaimer: the example was updated a few months ago to correct the error.

Best regards.


Av: Tony Yates 6. des 2018

RE: UserDefinedFieldInfoAgent and CurrentVersion

Thank you, Tony. You made my day!

Av: Arild Eik 6. des 2018

RE: UserDefinedFieldInfoAgent and CurrentVersion

Hi guys,

Sorry for responding to this post from 2018 but I have slightly different issue and I don't understand the answer given by Tony here that might also be helpful to my case.

I'm getting this error back from udfAgent.SaveUserDefinedFieldInfo(udField);

"ProgId not unique"

and only in the SoExceptionInfo class, which is unavailable to me in code ? but shows at runtime when the code breaks on error. Do I need to install/update anything more for the SoExceptionInfo to be available in code so I can log it to the DB ?

I'm testing the provisioning, so most times the fields are already present, and then I just want to update them.

The summary for SaveUserDefinedFieldInfo says :

"Updates the existing UserDefinedFieldInfo or creates a new UserDefinedFieldInfo if the id parameter is empty"

So I would expect the userdefined field to be updated if the ProgId is already there, and not get an error back saying "ProgId not Unique" which makes it impossible to update the field ?

Have I misunderstood something ? I have also looked around in the referencepages but didn't get any wiser.


and I cannot find any the "CreateDefaultUserDefinedFieldInfo" in the provisioning library linked in Tony's answer above ?


Br and thx.

Lars :)

Av: Lars Lykke 2. jan 2020

RE: UserDefinedFieldInfoAgent and CurrentVersion

It is not looking at the ProgId field, it is looking at the UDefFieldId field.

So you need to make sure that the UDefFieldId is filled in for the create-or-update logic to kick in.

The REST API makes this clearer: vs

In other words, don't create the info from scratch, go ask for a new field:


Av: Christian Mogensen 2. jan 2020

RE: UserDefinedFieldInfoAgent and CurrentVersion

Hi Christian, thanks very much for clearing my misunderstanding, I totally missed the UDefFieldId field, hopefully that solves it and yes as you hint we are using an older codebase unfortunately, I'm 4 months along the proces of learning SuperOffice coding and upgrading the codebase at the same time as fixing critical bugs and coding a whole new app :) Not an easy task for anyone new to the SuperOffice world :)



Av: Lars Lykke 3. jan 2020

RE: UserDefinedFieldInfoAgent and CurrentVersion

Been thinking about how I missed the right id field and it's probably since it's not used in the CreateOrUpdateUserDefinedField Proc, so you guys should probably update the SuperOffice.DevNet.Online/Source/SuperOffice.DevNet.Online.Provisioning

projekt on GitHub, since as of now, it won't update any fields, it can only create new fields (once), since the UDefFieldId is not being set.


I fixed it with this line :

udField.UDefFieldId = GetUserDefinedFields(owner).Where(x => x.ProgId == progId).FirstOrDefault().UDefFieldId;

Since ProgId seems to be unique, if there is a more correct way of doing that, please let me know :)


Av: Lars Lykke 6. jan 2020