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, ...
Suggested Answer

In X++ insert hard code value.

(0) ShareShare
ReportReport
Posted on by 1,215

Hi all,

i have an one setup form.

Calculations.PNG

As shown in the picture above, EOS record same header and line value 4 row i want to when i click generate setup it will come.

line 4 how to hard code i'm wondering.

Header : MPEoSSetups.

Line    :  MPEoSLevels.

in the "generate setup" dialog i have an calculation ID its mandatory that  calculation ID field come in the "MPcalculation" table.

public void clicked()
        {
            DialogField         fld;
            Dialog              dlg = new Dialog("Generate setup");
            MPEOSLevels        copyFrom, newlines;
            MPEoSSetups         header;
            MPCalculations      Calculations;
            MPCalculationId         calc;
            int                     ct;
        
            fld = dlg.addField(extendedTypeStr(MPCalculationId));
            if(dlg.run())
            {
                calc = fld.value();
                if(calc)
                {
                    while select Calculations
                        where Calculations.MPCalculationId == calc
                    {
                        select firstonly copyFrom
                            where copyFrom.MPEoSSetup == MPEoSSetups.MPEoSSetup;
                        if(copyFrom)
                        {
                           // copyFrom.MPEoSRangeId = "1"; 
                           // copyFrom.Description = "0-2";
                           // copyFrom.NumOfDays = 15;
                           // copyFrom.insert();
                           i'm wondering how to make that happen here.
                        }
                    }
                }
            }
            super();

Thanks 

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Hardcoded values are inserted just like any other values.

    Table.Field = [value];

    But I don't think that I understand your question. Could you try to describe it in an easier way? Do you really need hardcoded values, or are you talking about copying a value from one table to another table?

    Lately you have asked a couple of questions about simple data manipulation. Have you already read the documentation? docs.microsoft.com/.../xpp-data-home-page

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for replay sir,

    its not copying a value... its By default value available value in setup form

    in header

    1. end of selfservice(EOS)

    2. description(EOS)

    Line

    As i mentioned above the screen shot 4 line same record and same value while a "generate setup"

    same record i need it. how to do ?

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Hi Riyas,

    if it's not about copying, then why in your code you have a variable called copyFrom, and you select records from it?

    It must be confusing to you, but at least it's confusing to us, if your own code contains misleading stuff.

    Also, if you have some code that generates default setup, you should put it in a new class, not inside a clicked method of a button.

    If I now understand correctly, you want to create 4 setup lines when your user clicks the "Generate setup" button. Correct? And you want to use hard coded values for those fields. 

    And you don't know how to create records. I suggest you to read the documentation that I shared in my previous post.

    Once you are familiar with it, you are ready to write code that creates records. Here's some pseudo code to help you:

    public void clicked()
    {
        MyLine myLine;
        
        // Create first setup line
        myLine.clear();
        myLine.Field1 = [value that you want to put in field 1];
        myLine.Field2 = [value that you want to put in field 2];
        // Repeat until you have populated all fields that you want to populate
        myLine.insert();
        
        // Create second setup line
        myLine.clear();
        myLine.Field1 = [value that you want to put in field 1];
        myLine.Field2 = [value that you want to put in field 2];
        // Repeat until you have populated all fields that you want to populate
        myLine.insert();
        
        // Create third setup line
            myLine.clear();
        myLine.Field1 = [value that you want to put in field 1];
        myLine.Field2 = [value that you want to put in field 2];
        // Repeat until you have populated all fields that you want to populate
        myLine.insert();
        
        // Create fourth setup line
            myLine.clear();
        myLine.Field1 = [value that you want to put in field 1];
        myLine.Field2 = [value that you want to put in field 2];
        // Repeat until you have populated all fields that you want to populate
        myLine.insert();
    }

    Is it now clear?

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your answer sir,

    if i did same but header only inserted line not insert below my code.

    public void clicked()
            {
                DialogField         fld;
                Dialog              dlg = new Dialog("Generate setup");
                //MPEOSLevels        copyFrom, newlines;
                //MPEoSSetups         header;
                MPCalculations      Calculations;
                MPCalculationId         calc;
                int                     ct;
    
    
    
                fld = dlg.addField(extendedTypeStr(MPCalculationId));
                if(dlg.run())
                {
                    calc = fld.value();
                    if(calc)
                    {
                        while select Calculations
                            where Calculations.MPCalculationId == calc
                        {
           header               MPEoSSetups.MPEoSSetup = "EOS";
                                MPEoSSetups.Description = "EOS";
                                MPEoSSetups.insert();
                            
            Line                MPEOSLevels.MPEoSRangeId = "1";
                                MPEOSLevels.Description = "0-2";
                                MPEOSLevels.NumOfDays = 15;
                                MPEOSLevels.MPCalculationId = "E";
                                MPEOSLevels.FromNumOfYears = 0;
                                MPEOSLevels.ToNumOfYears = 2;
                                MPEOSLevels.PrevYearsNumOfDays =0;
                                MPEOSLevels.insert();
    
                                MPEOSLevels.MPEoSRangeId = "2";
                                MPEOSLevels.Description = "2-5";
                                MPEOSLevels.NumOfDays = 15;
                                MPEOSLevels.MPCalculationId = "y";
                                MPEOSLevels.FromNumOfYears = 0;
                                MPEOSLevels.ToNumOfYears = 2;
                                MPEOSLevels.PrevYearsNumOfDays =0;
                                MPEOSLevels.insert();
    
                                MPEOSLevels.MPEoSRangeId = "3";
                                MPEOSLevels.Description = "5-10";
                                MPEOSLevels.NumOfDays = 15;
                                MPEOSLevels.MPCalculationId = "u";
                                MPEOSLevels.FromNumOfYears = 0;
                                MPEOSLevels.ToNumOfYears = 2;
                                MPEOSLevels.PrevYearsNumOfDays =0;
                                MPEOSLevels.insert();
    
                                MPEOSLevels.MPEoSRangeId = "4";
                                MPEOSLevels.Description = "10-99";
                                MPEOSLevels.NumOfDays = 15;
                                MPEOSLevels.MPCalculationId = "S";
                                MPEOSLevels.FromNumOfYears = 0;
                                MPEOSLevels.ToNumOfYears = 2;
                                MPEOSLevels.PrevYearsNumOfDays =0;
                                MPEOSLevels.insert();
                            
                       }
                    }
                }
                MPEoSSetups_ds.research(true);
                MPEoSSetups_ds.research(true);
                super();
     

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Hi Riyas,

    did you debug it?

    I would say that it's almost certain that it inserted the lines, if it inserted the header. You can check with table browser.

    But most likely you missed some critical field from your lines - the one that defines the relation to the correct header.

    You will avoid this issue by setting the required fields as mandatory in your table setup. Then you would see an error message and spot the issue.

    In situations like this you can always use table browser to compare data that you created manually from the form, and data that was created automatically by your code. This way you can spot the difference and fix your code.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans