1

In D365 form development, I like to get the value entered to the form control, the form control is a form reference group control with Party reference field.

How to get the value entered to the control ?

tried with:

ReferenceGroup.controlNum(i).valueStr();

FieldBinding with filterValue

both also not work.

enter image description here

CSL
  • 75
  • 1
  • 6

1 Answers1

3

It should be as simple as calling the value() method on the FormReferenceGroupControl object to get the underlying Reference value (int64) which is the RecId of the underlying datasource. For example:

FormReferenceGroupControl referenceGroupControl;

referenceGroupControl = element.control(element.controlId(formControlStr(ReferenceGroupTestingForm, ReviewHeaderInfo_CustomsRepRefGroup))) as FormReferenceGroupControl;

referenceGroupControl.value(); //returns the RecId of the DirPerson table displayed.

To get the Display value which is substituted to the user instead of the underlying RecId value stored in the database, do this:

FormReferenceGroupControl referenceGroupControl;

referenceGroupControl = element.control(element.controlId(formControlStr(ReferenceGroupTestingForm, ReviewHeaderInfo_CustomsRepRefGroup))) as FormReferenceGroupControl;

//this gets the string control that is substituted in for the reference value/recid and displayed to the user. This is the second underlined control in the picture below. This control is determined by the ReferenceGroupControl property "Replacement Field Group" 
//Could be a different type of control than a String control depending on your scenario
FormStringControl subStringControl = referenceGroupControl.controlNum(1) as FormStringControl;

subStringControl.text(); //for string controls, text will contain the display value

enter image description here

One last thing to note is that I believe it is possible to get the values by manipulating datasource objects instead of formcontrol objects. I have seen solutions like this in the past while hunting through google search results. If I encounter them again I will update the answer

rjv
  • 1,058
  • 11
  • 29
  • Just in case we're solving the wrong problem, a much simpler way may be to refer to the table/datasource methods. `SalesTable.DeliveryPostalAddress` (Used as RefGroupControl) has a method `SalesTable.deliveryAddress()`, which you can call. – Alex Kwitny Aug 15 '19 at 18:17
  • I am not able to get the value using text(), is it because my reference group control does not have the StringEdit below it ? I cannot get from datasource because I want the value entered on the form, it could be some dirty value not exist in the database, right ? – CSL Aug 16 '19 at 04:01
  • 1
    Can you show a screenshot with your reference group? If it is a Party reference group, it must have a StringEdit control; if it is not, this explains why `valueStr()` does not work. – Aliaksandr Maksimau Aug 16 '19 at 09:25
  • @CSL the text() call is simply because the sub control created in my example by the MorphX designer when you drag/drop a reference group control and set the replacement field group property to (the default) AutoIdentification is a StringEdit control. For your situation you should find out what sub controls are auto created in your reference group. Like Aliaksandr said, share a screenshot of your form and we will be able to point out the correct method call. – rjv Aug 16 '19 at 13:55
  • I added a screenshot, it is when i directly drag the party field to the design. – CSL Aug 19 '19 at 05:28
  • Go to the underlying table of the datasource for the Party reference group control. Find the relation you created to the dirpartytable and double check to see it is correct. You have no display sub-control which is unusual, and that is why your call ReferenceGroup.controlNum(i).valueStr(); doesn't work (you are trying to call methods on an object/control that doesn't exist). If the relation is correct you should see the field groups of the dirpartytable in the drop down in your replacement field group property of the reference group control – rjv Aug 19 '19 at 13:25
  • So the problem is my table is not using foreign key relation but just relation. I am using field binding to retrieve my text in this case. Not sure if stringControl is needed if just normal relation, since it work too.. – CSL Aug 20 '19 at 02:50
  • additional question to the formreferencecontrol, is there a way to get the user value after the lookup form is shown? example in the control i type "123", then after the lookup pop out, i continue to type "123456". In my case i'm getting "123", but is it possible to get the "123456" ? – CSL Aug 20 '19 at 09:09
  • I'm not sure I fully understand you, but I'll make a few assumptions. If you are selecting "123" in the lookup then that is the value stored by the control, the lookup is just a result of the query. However, it may be possible that depending on what event/method you are attempting to find the value, you might be looking to early/late depending on your scenario. – rjv Aug 20 '19 at 17:07
  • In the Party lookup control, if I entered an invalid value, system will prompt "Unable to find a unique Global address book record corresponding to the entered values." Do I have a way to disable this prompt ? Right now I'm getting the control text during lookup method, that's why i cannot get the complete text. I'm trying to move it to modified but not working because of this warning. – CSL Aug 21 '19 at 02:59
  • This isn't the place for all these questions, so I this will be my last answer. If you have more questions, please create a new question instead of using these comments. To answer: you will need to create a custom lookup form if you want to the default out of the box lookup behaviour to change. There is documented guides out there on this subject. – rjv Aug 21 '19 at 13:59
  • Ok i will try on the suggestions.Thanks for the comments. – CSL Aug 22 '19 at 06:19