Hi,
I'm trying to assign the value of a formReferenceGroupControl
FormReferenceGroupControl name = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable_Name)) as FormReferenceGroupControl; HcmWorker hcmWorker = HcmWorker::findByPersonnelNumber(conPeek(con,counter)); -- hcmWorker has a value name.value(DirPartyTable::findRec(hcmWorker.Person).RecId); //it fails here
Hi, I think its failing because you are passing RecId in the name field. I am assuming name here is String field.
Try this code
name.value(DirPartyTable::findRec(hcmWorker.Person).Name);
Hi Mohit,
Name is a reference group as u can see from the code..so it's a recId but the form display it as string..so shall I use what you suggested?
The title of the thread mentions a NullReferenceException. If that's what you're getting, you must find which exact place of your code is throwing it. When you know where you have null instead of an object reference, we can start talking about why and how to address it.
Nevertheless I see the bug in this case. You're wrong in thinking that DirPartyTable_Name is a reference group. It's a string edit control; the reference group control is called DirPartyTable.
When you use the 'as' operator to case DirPartyTable_Name control to FormReferenceGroupControl, you'll get null, because the types aren't compatible. And you'll get an exception when trying to call value() on null.
You would have immediately seen the problem if you simply run your code in debugger, rather then going to a forum.
Hi Mohit and Martin,I tried this but the value is still not set in the form
[FormControlEventHandler(formControlStr(CaseDetailCreate, OK), FormControlEventType::Clicked)] public static void OK_OnClicked(FormControl sender, FormControlEventArgs e) { FormStringControl name = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable_Name)) as FormStringControl; //more logic HcmWorker hcmWorker = HcmWorker::findByPersonnelNumber(conPeek(con,counter)); -- hcmWorker has a value name.text(DirPartyTable::findRec(hcmWorker.Person).Name); }
I think that trying to set the name directly isn't a good idea. You should set the value of the reference group control.
Hi Martin,
But at first I was using formReferenceGroupControl and then you said it's wrong.
Can you please explain more what I should do...maybe I misunderstood you
No, you weren't. You were using the same control as now, DirPartyTable_Name, which isn't a reference group control. It's a string edit control.
As I said in my first reply, the reference group control is called DirPartyTable.
Hi Maritn,You mean you want it like this? -- it's still not working, the value is not filled in the form
[FormControlEventHandler(formControlStr(CaseDetailCreate, OK), FormControlEventType::Clicked)] public static void OK_OnClicked(FormControl sender, FormControlEventArgs e) { FormReferenceGroupControl name = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable)) as FormReferenceGroupControl; //more logic HcmWorker hcmWorker = HcmWorker::findByPersonnelNumber(conPeek(con,counter)); -- hcmWorker has a value name.value(DirPartyTable::findRec(hcmWorker.Person).RecId); }
Yes, this code now access the right control and sets a value there.
But it doesn't mean that it makes sense. The button closes the form, doesn't it? So how you can whether the value was set or not, if the form is closed and you can't see anything?
Also, we can't know whether your code finds any worker.
Hi Martin,here's the full code. When the button for "CaseDetailCreate" form closes it opens the caseDetail FormThe worker field is filled
[FormControlEventHandler(formControlStr(CaseDetailCreate, OK), FormControlEventType::Clicked)] public static void OK_OnClicked(FormControl sender, FormControlEventArgs e) { FormStringControl worker = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, XXWorker)) as FormStringControl; FormReferenceGroupControl caseCategory = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, CaseCategoryHierarchyDetail_CaseCategory)) as FormReferenceGroupControl; FormReferenceGroupControl name = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, DirPartyTable)) as FormReferenceGroupControl; FormRun formRun = sender.formRun(); FormDataSource formDataSource = formRun.dataSource(formDataSourceStr(CaseDetailCreate, CaseDetailBase)); CaseDetailBase caseDetailBase = formDataSource.cursor(); CaseAssociation caseAssociation; if(worker.text() != '') { Container con; SysLookupMultiSelectCtrl multiSelectCtrl = formRun.XXMultiSelectCtrl(); con = multiSelectCtrl.getSelectedFieldValues(); int counter; for(counter=1; counter <= conlen(con); counter ) { caseAssociation.EntityType = CaseEntityType::Employee; caseAssociation.CaseRecId = caseDetailBase.RecId; HcmWorker hcmWorker = HcmWorker::findByPersonnelNumber(conPeek(con,counter)); caseAssociation.RefRecId = hcmWorker.RecId; CaseCategoryHierarchyDetail caseCategoryHierarchyDetail; select firstonly caseCategoryHierarchyDetail where caseCategoryHierarchyDetail.RecId == caseCategory.value() && caseCategoryHierarchyDetail.XXIsPrimary == NoYes::Yes; if(caseCategoryHierarchyDetail) { caseAssociation.IsPrimary = NoYes::Yes; name.value(DirPartyTable::findRec(hcmWorker.Person).RecId); } caseAssociation.insert(); } } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 683 Most Valuable Professional
André Arnaud de Cal... 563 Super User 2025 Season 2
Sohaib Cheema 398 User Group Leader