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

access to caller form datasource values

(0) ShareShare
ReportReport
Posted on by 793

Hello,

I have a form BomPartOf. From it I call form BomConsistOf.

I need to make some formcontrols editable or not editable depending on the calling form name (in my case it is BomPartOf). How to achieve that? I need to write something like this on the called form BomConsistOf:

element.args().caller().

But after that I don't know how to refer to form's BomPartOf name. Applying to 

element.args().receord().tableid

is not an option as I see because I need to be sure that this logic will work only if BomConsistOf is called from BomPartOf form precisely. So I need to refer to the NAME of the form BomPartOf.

Also I need to get buffer of the bomVersion datasource table on the form BomPartOf (it's not a main datasource, main datasource of the form BomPartOf is BOM). HOw to do that?

Thanks.

 

  • dark_knight Profile Picture
    dark_knight 793 on at
    RE: access to caller form datasource values

    It works. Thanks for all your aswers&

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: access to caller form datasource values

    Hi Azat,

    Without changing the data source on the menu item, you could try this and see if it works.

    BomVersion  bomVersion;
    FormRun     callerForm = element.args().caller();
    
    bomversion = callerForm.datasource("BomVersion").cursor();

  • dark_knight Profile Picture
    dark_knight 793 on at
    RE: access to caller form datasource values

    Thank you. That's what I was searching for. Also Martin about buffer BomVersion that I need. In the datasource property of the menuitem button BomConsistOf on the form BomPartOf it's pointed out "Bom" by default and even when I change it to BomVersion to have a buffer I need in the element.args().record() I have Bom buffer, not BomVersion. Is there any way to refer to  BomVersion datasource of the caller without changing datasource property of the menuitembutton?

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,403 Most Valuable Professional on at
    RE: access to caller form datasource values

    Yes, it's throw an error, therefore you should check if the caller is a form before trying to call the method.

    For example:

    if (element.args().caller() && classIdGet(element.args().caller()) == classNum(FormRun))
    {
        FormRun callerForm = element.args().caller();
        callerForm.name();
    }

  • dark_knight Profile Picture
    dark_knight 793 on at
    RE: access to caller form datasource values

    I mean this place:

    if (element.args().caller().name() == formStr(BomConsistsOf))
    {
        // Logic when called from form "BomConsistsOf"
    }

    AX will  try to find method name() of the caller to make comparison, right? Since class doesn't have name() method it will throw an error, won't it?

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: access to caller form datasource values

    You need not know as well. Here you are checking if the caller form is "BomConsistsOf" and executing your logic there. If this statement returns false, the form is opened as it was working before. So, nothing breaks in the form.

  • dark_knight Profile Picture
    dark_knight 793 on at
    RE: access to caller form datasource values

    If it will be class it will throw an error since class doesn't contain method name()

  • dark_knight Profile Picture
    dark_knight 793 on at
    RE: access to caller form datasource values

    OK. I can't be sure that any class doesn't call my childform, right? I don't know all the system. So how can I be sure?

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: access to caller form datasource values

    Hi Azat,

    normally you whould know where all the form is being called from and you can handle this with an "if" statement like I already mentioned in an earlier reply.

  • Andre Ghazaleh Profile Picture
    Andre Ghazaleh 870 on at
    RE: access to caller form datasource values

    Even in this code:

    Form сallingForm;
    str name;
    
    callingForm = element.args().caller();
    name = callingForm.name();

    If the caller is not a form you will get runtime error, element.args().caller().name() is the same, the only difference is the IntelliSense.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans