Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Call modified method of form control from another modified method of a form control

Posted on by 278
Hello everyone,
 
We have a form that was created to enter items more easily.  On that form we have Item Group, Major Group, Minor Group and Item Template.
 
Right now, under the form control of Item Template, I have overwrote the modified method so that it finds the settings of the chosen Item Template and fills in the form accordingly.  This works perfectly.
 
After a user it tabbing through and fills out Item Template, and Major Group, then it looks up what Item Template is chosen for that combination and fills it in.  It does this in the modified method of Major Group.
 
I want it to execute the modified method of Item Template as soon as that happens so the rest of the form is filled out correctly.  I had this working by using element.redraw() and then calling the modified method, but if I change the major group after that, the item template doesn't update.
 
For example
Let's say I have Item Group IG001
And two Major Groups  MG001 and MG002

IG001 and MG001 use Item Template IT001
IG001 and MG002 use Item Template IT002
 
Also IT001 has Phantom set to yes
IT002 has Phantom set to no
Phantom is a setting for items and is on the form
 
So if a user tabs through, fills in IG001 and MG001, then using the modified method of major group, I am able to fill out item template with IT001.  I will post the code below.
 
Now if I use the code element.redraw() and call the modified method of item template, then it works and fills out Phantom correctly, but if I go back and change MG001 to MG002, the item template doesn't change even though it hits the code.
If I get rid of element.redraw() and the line calling the modified method, then the item template will update as soon as I choose the Major Group.
 
I need both things to work.  Hopefully this all makes sense.  I tried to give us much detail as possible....
  • Suggested answer
    Andrew Huisman Profile Picture
    Andrew Huisman 278 on at
    Call modified method of form control from another modified method of a form control
    Hi Layan,
     
    Yes, your code did help after I put the method on the datasource field. Thank you and I will mark your post as one of the answers.
     
    Here is my code on the datasource field
    /// <summary>
                ///
                /// </summary>
                public void modified()
                {
                    AMInventItemTemplate    amInventItemTemplate;
                    
                    super();
    
                    //Create a new query
                    Query                   query = new Query();
                    QueryBuildDataSource    queryBuildDataSource;
                    QueryBuildRange         queryBuildRange;
                    QueryRun                qr;
    
                    //Specify the name of the table the lookup should show data from.
                    queryBuildDataSource = query.addDataSource(tableNum(AMInventItemTemplate));
                    queryBuildRange = queryBuildDataSource.addRange(fieldNum(AMInventItemTemplate,TemplateId));
                    queryBuildRange.value(queryValue(TCI_ItemTable.TemplateNumber));
                
                    qr = new QueryRun(query);
       
                    while (qr.next())
                    {
                        amInventItemTemplate = qr.get(tablenum(AMInventItemTemplate));
                        TCI_ItemTable.CoverageGroup = amInventItemTemplate.ReqGroupId;
                        TCI_ItemTable.InventorySite = amInventItemTemplate.InventSiteId;
                        TCI_ItemTable.Phantom = amInventItemTemplate.Phantom;
                    }
                }
    And here is my code on the form grid control that calls this method
    public boolean modified()
            {
                boolean ret;
                AMInventItemMajorGroup  amInventItemMajorGroup;
        
                ret = super();
    
                TCI_ItemTable.TemplateNumber = '';
                TCI_ItemTable.MinorGroup = '';            
                TCI_ItemTable.CoverageGroup = '';
                TCI_ItemTable.InventorySite = '';
                TCI_ItemTable.Phantom = NoYes::No;
    
                //Create a new query
                Query                   query = new Query();
                QueryBuildDataSource    queryBuildDataSource;
                QueryBuildRange         queryBuildRange, queryBuildRange2;
                QueryRun                qr;
    
                //Specify the name of the table the lookup should show data from.
                queryBuildDataSource = query.addDataSource(tableNum(AMInventItemMajorGroup));
                queryBuildRange = queryBuildDataSource.addRange(fieldNum(AMInventItemMajorGroup,MajorGroupId));
                queryBuildRange.value(queryValue(TCI_ItemTable.MajorGroup));
                queryBuildRange2 = queryBuildDataSource.addRange(fieldNum(AMInventItemMajorGroup,ItemGroupId));
                queryBuildRange2.value(queryValue(TCI_ItemTable.ItemGroup));
                
                qr = new QueryRun(query);
       
                while (qr.next())
                {
                    amInventItemMajorGroup = qr.get(tablenum(AMInventItemMajorGroup));
                    TCI_ItemTable.TemplateNumber = amInventItemMajorGroup.ItemTemplateId;
                }
    
                TCI_ItemTable_ds.object(fieldNum(TCI_ItemTable, TemplateNumber)).modified();
    
                return ret;
            }
    
        }
     
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Call modified method of form control from another modified method of a form control
    Hi Andrew,

    Can you share the new code?
    And did the line of code i shared regarding datasource helped you? if yes then please mark answers that helped you as verified (if there were any)

    Thanks,
    Layan Jweihan
     
  • Suggested answer
    Andrew Huisman Profile Picture
    Andrew Huisman 278 on at
    Call modified method of form control from another modified method of a form control
    Yes that is all correct.
     
    I've continued working and moved the modified code to the modified method on the datasource field instead and it works great
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Call modified method of form control from another modified method of a form control
    Hi Andrew,
     
    By "bound to datasource" i meant, does this "item template" control has it's "data source" property filled?
     
    So I'm assuming you have a table that has the following fields:
    ItemGroupId, itemTemplateId, MajorGroupId, MinorGroupId
     
    and I would say:
    - ItemGroupId has a relation with InventItemGroup table
    - ItemTemplateId has a relation with with a certain table related to templates
    - MajorGroupId has a relation with with InventItemGroup & a certain table related to major groups
    - MinorGroupId has a relation with with InventItemGroup & a certain table related to minor groups
    right?
     
    and now you added this table to a form, where those 4 fields were included?


    Thanks,
    Layan Jweihan
  • Andrew Huisman Profile Picture
    Andrew Huisman 278 on at
    Call modified method of form control from another modified method of a form control
    I just tried what you said, but it didn't work.  But I'm assuming you need me to move my modified method code off the control and onto the datasouce field.  I can try that but I'm still curious how to get it to work the way I have it.
  • Andrew Huisman Profile Picture
    Andrew Huisman 278 on at
    Call modified method of form control from another modified method of a form control
    The methods are all bound to the control and not the datasource.  I don't want to affect it in other places, just this control.
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    Call modified method of form control from another modified method of a form control
    Hi Andrew,
     
    Is the control that you call it's modified method bound to a datasource?
     
    If yes maybe try sth like this instead of calling the control directly or using redraw. Replace the below example with your correct datasource and correct fields:
    taxWithholdTrans_ds.object(fieldnum(taxWithholdTrans, TaxWithholdCode)).modified();  
     
    Sorry I didn't read the whole details u wrote but hopefully it will help..let us know
     
    Thanks,
    Layan Jweihan
  • Andrew Huisman Profile Picture
    Andrew Huisman 278 on at
    Call modified method of form control from another modified method of a form control
    Here is the code
     
    public boolean modified()
            {
                boolean ret;
                AMInventItemMajorGroup  amInventItemMajorGroup;
        
                ret = super();
    
                TCI_ItemTable.TemplateNumber = '';
                //element.redraw();
    
                //TCI_ItemTable.MinorGroup = '';
                
                //TCI_ItemTable.CoverageGroup = '';
                //TCI_ItemTable.InventorySite = '';
                //TCI_ItemTable.Phantom = NoYes::No;
    
                //Create a new query
                Query                   query = new Query();
                QueryBuildDataSource    queryBuildDataSource;
                QueryBuildRange         queryBuildRange, queryBuildRange2;
                QueryRun                qr;
    
                //Specify the name of the table the lookup should show data from.
                queryBuildDataSource = query.addDataSource(tableNum(AMInventItemMajorGroup));
                queryBuildRange = queryBuildDataSource.addRange(fieldNum(AMInventItemMajorGroup,MajorGroupId));
                queryBuildRange.value(queryValue(TCI_ItemTable.MajorGroup));
                queryBuildRange2 = queryBuildDataSource.addRange(fieldNum(AMInventItemMajorGroup,ItemGroupId));
                queryBuildRange2.value(queryValue(TCI_ItemTable.ItemGroup));
                
                qr = new QueryRun(query);
       
                while (qr.next())
                {
                    amInventItemMajorGroup = qr.get(tablenum(AMInventItemMajorGroup));
                    TCI_ItemTable.TemplateNumber = amInventItemMajorGroup.ItemTemplateId;
                }
    
                //TCI_ItemTable_TemplateNumber.modified();
    
                return ret;
            }
     

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans