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

access to caller form datasource values

(0) ShareShare
ReportReport
Posted on by 942

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.

 

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Azat,

    Please try this code -

    if (element.args().caller().name() == formStr(BomConsistsOf))
    {
        \\Your logic here
    }

    As for getting the buffer of BomVersion, Have you set a datasource on the menuitem on the button in the parent form? If you set the data source to BomVersion, you can access it here.

    BomVersion bomVersion;
    
    bomVersion = element.args().record();

  • dark_knight Profile Picture
    942 on at

    Hi Gunjan,

    I need to get the name BomPartOf so the name of the from that called BomConsistOf so the code above is not correct for me.

    I did it like that

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

    This code above gives me the name "BomPartOf".

    That's what i need but the question is why this code:

    element.args().caller().name()

    mentioned by you doesn't work. It doesn't find method name().

    Also my code will throw an error if the form will be called from class, for instance. Because callingForm variable is Form variable not a class. So I also need to somehow check that my form is called from form.

    This way is not a good way as I see:

    As for getting the buffer of BomVersion, Have you set a datasource on the menuitem on the button in the parent form? If you set the data source to BomVersion, you can access it here.

    BomVersion bomVersion;
    
    bomVersion = element.args().record();

    If I change property datasource on the button on the parentfrom can it be sow that in sp,e code on the child form buffer BOM is needed instead of BomVersion? IN that case I\ll break other logic

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Azat,

    It doesn't provide the method Name() in intellisense, but it will not throw an error and you can use this to check if the form is being called from another form or class. Please check this post.

    Let's say this form is called from a class as well. In that case your code will look like this -

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

    You can't set the data source on the actual menu item. You only have this property available on the button in a form. So, in the form BOMConsistsOf, you have a button which opens this new form (where you are writing your code). On this button in the BomConsistsOf form, you can mention the datasource property to "BomVersion".

  • dark_knight Profile Picture
    942 on at

    OK. Thanks a lot. If I set datasource property to BOMVersion I'll be able to get the correct buffer but can it be sow that in some code on the child form buffer BOM is needed instead of BomVersion? IN that case I'll break other logic?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Azat,

    You can query for the BOM table buffer. Correct? Based on BOMVersion.BOMId.

  • dark_knight Profile Picture
    942 on at

    I suppose yes I can. Correct but I simply don't know where to do this since I don't know all the code the called from uses. Or maybe I should do this proactively in some method in order to have bom buffer? Just in case.

  • Verified answer
    Andre Ghazaleh Profile Picture
    870 on at

    Hi Azat,

    The reason it doesn't find the .name() method is because .name() is not defined for all callers, if the caller is formrun, formrun has the .name() method and so the code runs.

    If the caller is for example a class you get error.

    In your code you assume it's a form and assign the element.args().caller() object to this form, that's why you find the name method in the editor.

    Regards.

  • dark_knight Profile Picture
    942 on at

    thanks. in that case I can't simply write

    element.args().caller().name()

    because if that will be class I will get an error. Is there any way to check that caller is form precisely and not a class?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Azat,

    Not sure what you mean by the code "calledFrom" uses. In this case, if you pass bomVersion as the datasource it makes more sense as it is the child table and you should be able to find the parent table using a query. You can find some more examples here on how to use caller object for a form.

  • Andre Ghazaleh Profile Picture
    870 on at

    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

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 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans