web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

how to filled fields in a new form

(0) ShareShare
ReportReport
Posted on by 5

I have a Kalibrace2 button on the InventTable form.

pastedimage1627483549596v2.png

If I click on this button, a new form should open with  filled fields Cislo Polozky(ItemID) and Nazev Polozky (ItemName). But only Cislo Polozky(ItemId) field looks like filled.

pastedimage1627483558299v3.png

 

Here is my project tree

pastedimage1627483567005v4.png

 

Here is the content of the InitValue method. But this.CisloPolozky has an empty value.

 pastedimage1627483576372v5.png

 

 Could anybody help how to reach my goal to have a filled fields CisloPolozky(ItemId) and NazevPolozky(Itemname) in my form Kalibrace?

Is it better to use methods or make relationship between Kalibrace and InventTable?

The relationship InventTalbe.ItemId=Kalibrace.CisloPolozky and InventTable.ItemName=Kalibrace.NazevPolozky is working but I think that it is not the correct way.

Thanks in advance.

Vladimír

 

I have the same question (0)
  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    You already have the inventTable, why are you trying find again?

    My guess is that the field you are assigning the ItemId to has insufficient characters. You can't find the InventTable in find because you couldn't save all of it.

    Second possibility ItemName is empty. This field has been removed in later versions. If you see the form's field filled, make sure it's the same field.(not nameAlies or display name)

    Examine the form/table's init/initvalue and insert/write methods. You may be override it somewhere.

    Finally, if the field is new, there may be a problem with synchronization.

  • Verified answer
    Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    According to your code, you should never get any value, because you're getting ItemId from a newly declared variable (at line 4) that you never populate with anything.

    I guess that your code has no effect at all and the value gets populated based on the relation defined between tables. The correct relation is just through ItemId, because that's the primary key of InventTable. If you have a good reason for duplicating ItemName in your table, initialize it below super() in initValue().

    If you wanted to set ItemId in code, you would need to get the caller InventTable record:

    InventTable inventTable = element.args().record();

    Just make sure that you call the form through a menu item. It's also good to explicitly set the DataSource property of the menu item button.

    By the way, you should always create element names in English. Maybe you don't see the need right now, but you can easily get into a situation when using other language causes problems. For example, your company will expand and people from other countries will need to work with your objects. Or maybe you'll want to outsource some work to another country. Or you'll decide to sell your solution to another company...

  • ergun sahin Profile Picture
    8,826 Moderator on at

    I agree that it must be in English, in its simplest form I just experienced it. I got lost in the words while I was examining. I didn't realize that InventTable was empty because I was thinking which was Item and which was ItemName

  • VladaVlada Profile Picture
    5 on at

    Hello Martin,

    Thanks a lot.

    I did the init method on Kalibrace form according to your advice and it works.

    The code looks like:

    public void init()
    {

    InventTable inventTableFromForm;
    ;
    super();

    if (element.args().record())
    {
    inventTableFromForm = element.args().record();
    Kalibrace.CisloPolozky = inventTableFromForm.ItemId;
    Kalibrace.NazevPolozky = inventTableFromForm.ItemName;

    }

    checkFailed(strfmt(Kalibrace.CisloPolozky + Kalibrace.NazevPolozky)); // here I can see the values from inventTable 

    }

    But I am not able to put that values into the fields in Kalibrace table.

  • Suggested answer
    Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    First of all, on which object is the init() method defined? It's most likely a wrong place. Both form's and data source's init() method is called just once, when the form is being loaded. The right method for initializing every new record is initValue().

    By the way, please always use Insert > Insert Code (in the rich formatting view) to paste source code:

    public void initValue()
    {
    	InventTable inventTableFrom = element.args().record();
    
    	super();
    
    	if (inventTableFrom)
    	{
    	    kalibrace.CisloPolozky = inventTableFrom.ItemId;
    	    kalibrace.NazevPolozky = inventTableFrom.ItemName;
    	}
    
    	info(kalibrace.CisloPolozky   kalibrace.NazevPolozky);
    }

  • VladaVlada Profile Picture
    5 on at

    Please see below where is the init method defined

    Kalibrace.jpg

  • Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    As I said, that's a wrong place. It's called just once, not every time when you create a record. Also, it happens before the query gets executed and records are loaded from database. That's a good thing in this case, because your code will just have no effect - otherwise you would be  overwritting values of the currently loaded record. That would be a critical bug.

    It seems to me that you aren't using the debugger, otherwise you would have a better idea about where your code gets called and what it does. You should start using it. Also, don't forget about the product documentation, such as Event Method Sequences in Form Scenarios.

  • VladaVlada Profile Picture
    5 on at

    The Kalibrace datasource is the right place for InitValue() method. I placed it there and it works how I need.

    Kalibrace2.jpg

    Now I don't need any relations between tables and have only kalibrace datasource. Exactly how I wanted.

    Thank you so much.

  • Martin Dráb Profile Picture
    237,963 Most Valuable Professional on at

    You're welcome. :)

    Having relations has many other benefits, therefore trying to avoid them isn't a particularly good idea.

    For example, they automatically join form data sources, allow easily setting join conditions in queries, lookup forms are generated from relations, data consistency can be checked based on relations and so on.

  • VladaVlada Profile Picture
    5 on at


    What if I have the same button Kalibrace2 on the form InventOnHandItem?


    I added a simmilar code, but it doesn't work properly. It works only when I create a new record in opened kalibrace form but not when I run the form from inventOnHandItem.(not during the initialization)


    public void initValue()
    {
    InventTable   inventTableForm = element.args().record();
    InventSum  inventSumForm = element.args().record();
    
    super();
    
    if (inventTableForm)
    {
     Kalibrace.CisloPolozky = inventTableForm.ItemId;
     Kalibrace.NazevPolozky = inventTableForm.ItemName;
    }
    
    if (inventSumForm)
    {
    Kalibrace.CisloPolozky = inventSumForm.ItemId;
    Kalibrace.NazevPolozky = inventSumForm.itemName();
    
    }
    
    info(Kalibrace.CisloPolozky   Kalibrace.NazevPolozky);
    
    }

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans