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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

To change the value in field when the data is inserted by entity

(1) ShareShare
ReportReport
Posted on by 1,836
hi , every one ,
on sales table form , there is custaccount field , and the data is coming from entity in this field now i want to change the value when the data is inserted in this field and take the value from the parameter field which is created on another form , can anyone plz suggest me how can i get this done .where should i write my code which method should i be using for this .
 
thanks ,
Regards,
Dinesh.
I have the same question (0)
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To change the value in field when the data is inserted by entity
    Hi Dinesh,
     
    Does this parameter contain values for custAccount as well? Or random string? I'm asking because there is a relation to custTable that might fail.
     
    In general, for importing you can try InsertEntityDataSource(if you are only interested in insert) or mapEntityToDataSource or postLoad ( i prefer to not use postLoad unless necessary so please give ur more info)
     
    Thanks,
    Layan Jweihan
     
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Dineshkarlekar Profile Picture
    1,836 on at
    To change the value in field when the data is inserted by entity
    hi, 
    Thanks for reply , 
    I have created the the same custaccount field on cust parameter form which will flow on salestable cust account at the time of insertion .is it possible to use insert method extension of salestable .
     
     
    Thanks,
    Regards,
    Dinesh
  • Dineshkarlekar Profile Picture
    1,836 on at
    To change the value in field when the data is inserted by entity
    hi , 
    i have made the code like this , can you plz suggest me how can is eleminate the unnecessary if condition ,below , is my code .
    [ExtensionOf(tableStr(SalesTable))]
    final class DTCustomerCodeSalesTable_Extension
    {
        void insert(boolean _skipMarkup)
        {
    
            this.custAccountModified();
            next insert(_skipMarkup);
        }
    
        void custAccountModified()
        {
            CustParameters       custParameters;
            SalesTable           salesTable;
    
            select firstonly DTCustomerCode from custParameters
                where custParameters.DataAreaId == this.DataAreaId;
    
            if(this.ISLFOC == NoYes::Yes)
            {
                if(custParameters.DTCustomerCode != "")
                {
                    if(custParameters.DTCustomerCode != this.CustAccount)
                    {
                        this.CustAccount = custParameters.DTCustomerCode;
                    }
                }
            }
        }
    }
    
    thsnks , 
    regards,
    Dinesh 
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To change the value in field when the data is inserted by entity
    Hi Dinesh,

    Didn't you say that you only want the code to work on entity level? If you do it on table level, then it means it's going to happen all the time, even if you do it from form -- or do you want this code to be applied if ISFLOC is true, regardless if you are inserting via data entity or form or anywhere?

    In general here's how you can make your code better
        void custAccountModified()
        {
            if(this.ISLFOC == NoYes::Yes)
            {
                CustParameters       custParameters;
                SalesTable           salesTable;
    
                select firstonly DTCustomerCode from custParameters; //no need for DataArea where condition
    
                if(custParameters.DTCustomerCode != "" && custParameters.DTCustomerCode != this.CustAccount)
                {
                        this.CustAccount = custParameters.DTCustomerCode;
                }
            }
        }

    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Dineshkarlekar Profile Picture
    1,836 on at
    To change the value in field when the data is inserted by entity
    [ExtensionOf(tableStr(SalesTable))]
    final class DTCustomerCodeSalesTable_Extension
    {
        void insert(boolean _skipMarkup)
        {
            FieldId _fieldId;
    
            this.modifiedField(_fieldId);
            next insert(_skipMarkup);
        }
    
        public void modifiedField(FieldId _fieldId)
        {
            next modifiedField(_fieldId);
             
            if (_fieldId == fieldNum(SalesTable, CustAccount))
            {
                this.custAccountModified();
            }
        }
        void custAccountModified()
        {
            CustParameters       custParameters;
            SalesTable           salesTable;
    
            select firstonly DTCustomerCode from custParameters
                where custParameters.DataAreaId == this.DataAreaId;
    
            if(this.ISLFOC == NoYes::Yes && custParameters.DTCustomerCode != "" && custParameters.DTCustomerCode != this.CustAccount)
            {
                        this.CustAccount = custParameters.DTCustomerCode;   
            }
        }
    }
    
    hi ,
    lyan , 
    thanks for corrections ,
    i have made some changes in my code can you plz tell me am i using modified field method right , 
     
    thanks,
    Regards,
    Dinesh
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To change the value in field when the data is inserted by entity
    Hi Dinesh,

    I can see you didn't follow my recommendations.

    I've put if(this.ISLFOC == NoYes::Yes) at the beginning of the method, because why waste time and select parameter table if this flag is no, i also suggested to remove DataAreaId from the select (you can test it to see if it's really needed or no). So please go back to the code i've put in the previous reply.

    You also didn't answer my question.  i will repeat it again here:
    "Didn't you say that you only want the code to work on entity level? If you do it on table level, then it means it's going to happen all the time, even if you do it from form -- or do you want this code to be applied if ISFLOC is true, regardless if you are inserting via data entity or form or anywhere?"

    If you want your code to be called regardless if you do it via entity or not, then leave the code at table level. And if you want the code in case of update or insert, then leave the modified method. Please put clear requirements, because u first said insert at entity level, then you put code at table level, then you put code in modified method which means update is now included.
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    To change the value in field when the data is inserted by entity
    When I am reading previous comments, I can see that information provided by you is not sufficient.
     
    As Layan suggested, you said, on entity import. But then you wrote code at insert of table which means action should trigger on all times like at form level too. And then you added code at modified and update.
     
    Can you give your exact requirement and then you can add your code here.
  • Dineshkarlekar Profile Picture
    1,836 on at
    To change the value in field when the data is inserted by entity
    hi , layan ,
    thanks for reply ,
     
    Actually , i was trying to pass the value in the field when the data gets inserted into sales table from entity  , insert method will hit i guess so at that time the field get modified by the value i am passing .that's what i am trying to do . 
     
     
    thanks ,
    Regards,
    Dinesh.
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To change the value in field when the data is inserted by entity
    Hi Dinesh,
     
    If you are only interested in insert, then you shouldn't put code in the modified method at table level as this will make the code be called when you update as well
     
    And if you are only interested in insert from entity. Then you shouldn't put code at Insert method at table level. Because this code will be called when you insert a sales order from the form as well and it seems you don't want that 
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Dineshkarlekar Profile Picture
    1,836 on at
    To change the value in field when the data is inserted by entity
    hi , 
    Everyone , i tried to import the data at sales table from salesorderheaderV3 entity and tried to flow the value when the in excel sheet when i made the foc pameter to yes  the data gets flow on sales table but i need to change field value , where should i do code because table extension insert method is not working .please help me on this .
     
     
     
    thanks,
    Regards,
    Dinesh

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans