cancel
Showing results for 
Search instead for 
Did you mean: 

Issue adding record to repeater based on MIKG on Unity form

Corey_Gillingha
Confirmed Champ
Confirmed Champ

Hi,

 

I am developing a Unity script (in C#) that adds a record to a repeater on a Unity form that is based on a MIKG.  The MIKG has two keywords, Member and Vote.  Here is the portion of the script that I have written to add a record to the repeater:

 

FormModifier form_mod = form.CreateUnityFormModifier();
FormTemplate template1 = app.Core.UnityFormTemplates.Find("TEST-Unity Form");
StoreNewUnityFormProperties uFormProps = app.Core.Storage.CreateStoreNewUnityFormProperties(template1);

KeywordRecordType keywordRecordType = app.Core.KeywordRecordTypes.Find("TEST-KW Rec Type");

 

EditableKeywordRecord editableKeywordRecord = keywordRecordType.CreateEditableKeywordRecord();

 

KeywordType keywordTypeCommiteeMember = keywordRecordType.KeywordTypes.Find("Member");
Keyword keywordCommiteeMember = keywordTypeCommiteeMember.CreateKeyword(New_Member);
editableKeywordRecord.AddKeyword(keywordCommiteeMember);

 

KeywordType keywordTypeVote = keywordRecordType.KeywordTypes.Find("Member Vote");
Keyword keywordVote = keywordTypeVote.CreateKeyword(New_Vote);
editableKeywordRecord.AddKeyword(keywordVote);

 

uFormProps.AddKeywordRecord(editableKeywordRecord);
form_mod.ApplyChanges();

 

I am not sure what I am missing, but the record does not get added to the repeater.  There are no errors and I have confirmed through display statements that I have valid values for the keywords to be added. 

 

Any help that could be provided to make this code work so that a record gets added to the repeater would be greatly appreciated.

 

Thank you,

Corey

1 ACCEPTED ANSWER

Felipe_Fonseca
Champ on-the-rise
Champ on-the-rise

Hello Corey! 

 

To these cases the best to do is contact your first line Support.

You can try to edit the KeywordModifier instead of FormModifier.

 

Could you please try the following?

If it doesn't work, I recommend you to contact your first line Support.

To this example I'm using I Worflow Unity Script.

OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)

 

 

KeywordRecordType keyRecType = app.Core.KeywordRecordTypes.Find("MemberVoteKTG");
if(keyRecType == null)
{
app.Diagnostics.Write("keyrectype == null");
}

KeywordType memberKeyType = keyRecType.KeywordTypes.Find("Member");
if(memberKeyType == null)
{
app.Diagnostics.Write("memberKeyType == null");
}

Keyword memberKeyword = memberKeyType.CreateKeyword("NewMember");

KeywordType voteKeyType = keyRecType.KeywordTypes.Find("Vote");
if(voteKeyType==null)
{
app.Diagnostics.Write("voteKeyType == null");
}

Keyword voteKeyword = voteKeyType.CreateKeyword("NewVote");

using(DocumentLock docLock = args.Document.LockDocument())
{
if(docLock.Status != DocumentLockStatus.LockObtained)
{
app.Diagnostics.Write("Lock false");
}

KeywordModifier keyModif = args.Document.CreateKeywordModifier();
EditableKeywordRecord editKeyModif = keyRecType.CreateEditableKeywordRecord();

editKeyModif.AddKeyword(memberKeyword);
editKeyModif.AddKeyword(voteKeyword);

keyModif.AddKeywordRecord(editKeyModif);
keyModif.ApplyChanges();
}

View answer in original post

6 REPLIES 6

Felipe_Fonseca
Champ on-the-rise
Champ on-the-rise

Hello Corey! 

 

To these cases the best to do is contact your first line Support.

You can try to edit the KeywordModifier instead of FormModifier.

 

Could you please try the following?

If it doesn't work, I recommend you to contact your first line Support.

To this example I'm using I Worflow Unity Script.

OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)

 

 

KeywordRecordType keyRecType = app.Core.KeywordRecordTypes.Find("MemberVoteKTG");
if(keyRecType == null)
{
app.Diagnostics.Write("keyrectype == null");
}

KeywordType memberKeyType = keyRecType.KeywordTypes.Find("Member");
if(memberKeyType == null)
{
app.Diagnostics.Write("memberKeyType == null");
}

Keyword memberKeyword = memberKeyType.CreateKeyword("NewMember");

KeywordType voteKeyType = keyRecType.KeywordTypes.Find("Vote");
if(voteKeyType==null)
{
app.Diagnostics.Write("voteKeyType == null");
}

Keyword voteKeyword = voteKeyType.CreateKeyword("NewVote");

using(DocumentLock docLock = args.Document.LockDocument())
{
if(docLock.Status != DocumentLockStatus.LockObtained)
{
app.Diagnostics.Write("Lock false");
}

KeywordModifier keyModif = args.Document.CreateKeywordModifier();
EditableKeywordRecord editKeyModif = keyRecType.CreateEditableKeywordRecord();

editKeyModif.AddKeyword(memberKeyword);
editKeyModif.AddKeyword(voteKeyword);

keyModif.AddKeywordRecord(editKeyModif);
keyModif.ApplyChanges();
}

Hi Felipe,

 

Thank you for this information!  My script is being called from a Custom Action on a Unity form.  Unfortunately, I do not have Document available to me for args (I only have FormInstance).  I am assuming this is because this is an  IUnityFormCustomActionEventScript script.  Do you have any suggestions on how I can create the KeywordModifer given that I do not have Document availabe for args?

 

Thank you,

Corey

Hyland.Unity.UnityForm.FormTemplate template = args.FormInstance.FormTemplate;
Hyland.Unity.UnityForm.Form form = args.FormInstance;


Hyland.Unity.UnityForm.FormModifier formModifier = form.CreateUnityFormModifier();

//ID membervotekt6 for KTG Item
Hyland.Unity.UnityForm.EditableRepeaterItem repeaterItem = template.AllFieldDefinitions.RepeaterDefinitions.Find("membervotektg6").CreateEditableRepeaterItem();
//ID member7 for Keyword Member Field
repeaterItem.SetFieldValue("member7", "New Member");
//ID vote8 for Keyword Vote Field
repeaterItem.SetFieldValue("vote8", "New Vote");


formModifier.AddRepeaterItem(repeaterItem);

formModifier.ApplyChanges();

I Hope it works.

As I said before, the best on this case is Contact you first line Support.