05-30-2019 10:42 AM
Hi everyone,
I have a Unity API that I want to fill in fields in a repeating section on a unity form. The API will select radio buttons within the repeating section. For instance the value of 1 is "Yes" and the value of 2 is "No". For some reason it works fine with one of the radio buttons but does not work for any other radio buttons.
Hyland.Unity.UnityForm.Form form2 = doc.UnityForm;
Hyland.Unity.UnityForm.FormModifier formMod = form2.CreateUnityFormModifier();
RepeaterDefinition repeaterDef = form2.FormTemplate.AllFieldDefinitions.RepeaterDefinitions.Find("repeatingsection111");
EditableRepeaterItem erd = repeaterDef.CreateEditableRepeaterItem();
erd.SetFieldValue("radiobuttongroup488", "2");
erd.SetFieldValue("radiobuttongroup150", "1");
formMod.AddRepeaterItem(erd);
formMod.ApplyChanges();
radiobuttongroup488 has "No" selected just fine but for radiobuttongroup150 nothing is selected when it should have "Yes" selected. There are no errors or exceptions, the code completes with no issue, its just not doing what is meant to be done.
Any and all advice is greatly appreciated!
05-31-2019 06:26 AM
Using the following code, I was able to set the values of all of the radio button groups.
var uftemp = app.Core.UnityFormTemplates.Find("RadioButtonTest");
StoreNewUnityFormProperties uFormProps = app.Core.Storage.CreateStoreNewUnityFormProperties(uftemp);
uFormProps.AddKeyword("Description", "Radio Button Test");
RepeaterDefinition repdef = uftemp.AllFieldDefinitions.RepeaterDefinitions.Find("repeater");
EditableRepeaterItem eri1 = repdef.CreateEditableRepeaterItem();
eri1.SetFieldValue("rbg1", "1");
eri1.SetFieldValue("rbg2", "0");
eri1.SetFieldValue("rbg3", "1");
eri1.SetFieldValue("textbox", args.Document.Name);
uFormProps.AddRepeaterItem(eri1);
Document newUnityForm = app.Core.Storage.StoreNewUnityForm(uFormProps);
Console.WriteLine(string.Format("Form Created: docid={0}.",newUnityForm.ID));
05-30-2019 11:06 AM
Hey Taylor! Thanks for getting in touch with us. I just wanted to check something -- if you flip the assignment of "1" and "2" does one behave properly and the other not, or are they both wrong? I'm curious because I'm not convinced that code is actually doing anything. Alternatively, it may be that the EditableRepeaterItem is only setting the first of the Fields in its list. Are both radio buttons in repeatingsection111? If so, what would happen if you were to loop the erd set->write->apply process like so?
EditableRepeaterItem erd1 = repeaterDef.CreateEditableRepeaterItem();
erd1.SetFieldValue("radiobuttongroup488", "2");
formMod.AddRepeaterItem(erd1);
formMod.ApplyChanges();
EditableRepeaterItem erd2= repeaterDef.CreateEditableRepeaterItem();
erd2.SetFieldValue("radiobuttongroup150", "1");
formMod.AddRepeaterItem(erd2);
formMod.ApplyChanges();
I'd be curious to see what the results are.
05-30-2019 01:01 PM
Hi Adam,
radiobutton488 works fine with 1 or 2 set as the value, it selects the appropriate "Yes" or "No. I actually have quite a few other radio buttons within the repeating section I'm trying to set the value for but it only works for the first radiobutton488 on the form. There are textboxes as well that I'm setting values for and those work just fine. None of the other radio buttons work regardless if it is 1 or 2., they're always blank.
I tried what you suggested and that did not work either.
05-31-2019 12:02 AM
Hi Taylor,
Adam logic looks. He missed number with erd in SetFiledValue.
Kindly check with below code.
EditableRepeaterItem erd1 = repeaterDef.CreateEditableRepeaterItem();
erd1.SetFieldValue("radiobuttongroup488", "2");
formMod.AddRepeaterItem(erd1);
formMod.ApplyChanges();
EditableRepeaterItem erd2= repeaterDef.CreateEditableRepeaterItem();
erd2.SetFieldValue("radiobuttongroup150", "1");
formMod.AddRepeaterItem(erd2);
formMod.ApplyChanges();
Also check with single item for radiobuttongroup150. check if it is working properly?
EditableRepeaterItem erd= repeaterDef.CreateEditableRepeaterItem();
erd.SetFieldValue("radiobuttongroup150", "1");
formMod.AddRepeaterItem(erd);
formMod.ApplyChanges();
05-31-2019 04:18 AM
Good catch, Amir!
Taylor -- I'm gonna try and replicate this; what version are you seeing this in? Also, just to be clear: you are creating a new Unity Form Instance with this script, not updating a Unity Form type Document that's already been indexed, right?
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.