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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Drop dialog update

(0) ShareShare
ReportReport
Posted on by 351

Hi all,

We have one custom form and that form i want to add one button(Renewal).

Old forms records.

1. worker
2. Name
3. no of amount.
4. total amount
5. ticket cost
6. valid from(effective date)
7. valid to (effective date)
8. contract number

New thing i want to do below steps.

1. worker
2. Name
3. no of amount.
4. total amount
5. ticket cost
6. valid from(effective date) (I want to change)
7. valid to (effective date) (i want to change)
8. contract number (I want to change)

Note :- it should be like copy records and update that 3 fields only and if we add it to that three fields already an available record in this case (i want to throw some error while click button new value only to accept).

The same form i add drop dialog button and there is four fields.

1. worker (don't change existing shows as an etc -(000005)
2. valid from(effective date) (I want to change)
3. valid to (effective date) (i want to change)
4. contract number (I want to change)

once i fill the value to drop dialog and it should be updated - 000005(that three records remaining value keep it as old) so that i wrote code.

            DialogField         dialog;
            Dialog              dlg = new Dialog("Renewal");
            Grades                 headerCopy;
            HcmWorkerRecid           worker;
              
        
            fld = dialog.addField(extendedTypeStr(HcmWorkerRecid)); // This EDT i don;t wanna select by default value i want to based on worker selected in custom worker aaginst.
            if(dialog.run())
            {
                worker = fld.value();
                if(worker)
                {
                    select firstonly headerCopy
                       where headerCopy.worker == worker;

                    if(headerCopy.RecId)
                    {
                        ttsbegin;
                        Grades.selectForUpdate(true);
                        Grades.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
			            Grades.Worker                   = headerCopy.Worker;
                        Grades.NumOfTicket              = headerCopy.NumOfTicket;
                        Grades.contractNo               = headerCopy.contract; //i fill as new value
                        Grades.TotalAmount              = headerCopy.TotalAmount;
                        Grades.Totalcost                = headerCopy.Totalcost;
                        Grades.Validfrom                = headerCopy.Validfrom; /i fill as new value
			            Grades.Validto                  = headerCopy.Validto;  /i fill as new value                                    
                        Grades.Update();
                        ttscommit;
                    }
                }

As i mentioned code i write in clicked method (grades) dataSource name.

Now, i want to drop dialog form how can i do that and in the drop dialog we need add (grades) dataSource? and that three fields already same value give it to i want to error hwo to do please give me on that.

Thanks 

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

    Hi waytod365,

    You can add the fields as controls and update the fields from form methods. Please check the form HcmEmploymentDialog as an example, as its functionality is very close to what you are trying to achieve. This form is opened from Workers > Employment history

    pastedimage1652003455426v1.png

    Under employment history, you can click on Edit dates.

    pastedimage1652003576125v2.png

  • waytod365 Profile Picture
    351 on at

    Thanks for you prompt replay sir,

    I saw that employment history and small confusion sir.

    Could you please give me control in dialog as i mentioned above code and validation plz.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    You can check the controls in the form design

    pastedimage1652004314270v1.png

    If you check the clicked method in the button, you should be able to see the validation code as well. You could write implement your form in the same way.

    pastedimage1652004421787v2.png

  • waytod365 Profile Picture
    351 on at

    Thanks for your approach sir,

    I saw there is used class level update that employment history (HcmPositionTransition class).

    I want to within clicked method update and validation sir so that i wrote a code its not update. code not working sir.

    Code ;-

     class ReNew
        {
            /// 
            ///
            /// 
            public void clicked()
            {
                Grades grades, gradesCopy;
                super();
                while select gradesCopy
                   where gradesCopy.ValidFrom == validfrom.dateValue()
                    && gradesCopy.ValidTo == validto.dateValue()
                    && gradesCopy.Worker == HcmWorker::findByPersonnelNumber(PersonnelNumber.text()).RecId
                {
                    select firstonly grades
                    where grades.ValidFrom == gradesCopy.ValidFrom
                    && grades.ValidTo == gradesCopy.ValidTo
                    && grades.Worker == gradesCopy.Worker;
    
                    if(grades.RecId)
                    {
                        ttsbegin;
                        grades.selectForUpdate(true);
                        grades.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                        grades.ValidFrom = gradesCopy.ValidFrom;
                        grades.ValidTo = gradesCopy.ValidTo;
                        grades.ContractPeriod = gradesCopy.ContractPeriod;
                        grades.update();
                        ttscommit;
                    }
                }
            }
    
        }

    As i mentioned above code i did't do validation.

    Leg.PNG

    As i highlighted yellow color i want to in dialog (000001) but its not show and i set that drop down menuitem (grades) dataSource in my details master form.

    Note :- Validation an already (000001) against valid from and valid to also contract has it in records. while dialog if i give it to same date and contract i want to tell (error :- The record exists already fill as a new). 

    Thanks for your time.

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

    To get the worker personnel Id, please check the init method of the HcmEmploymentDialog form. if HcmWorker is the caller form for you, you can write your init method like this -

    public void init()
    {
        if (element.args() && element.args().caller())
        {
            if (element.args().dataset() == tableNum(HcmWorker))
            {
                hcmWorker = element.args().record();
                PersonnelNumber.text(hcmWorker.PersonnelNumber);
            }
        }
    
        if (!hcmWorker)
        {
            element.lifecycleHelper().exitForm(Error::missingFormActiveBuffer(element.name(), tableStr(HcmWorker)));
        }
    
        super();
    }

    Please make sure that hcmWorker table buffer is declared in the form.

    Regarding the update method, I am not sure why you are trying to do a while select for the grades table. But the basic idea will be like this -

    public void clicked()
    {
        Grades                 headerCopy;
        HcmWorkerRecid           worker;
        
        select firstonly forupdate headerCopy
           where headerCopy.worker == hcmWorker.RecId;
    
        if(headerCopy)
        {
            ttsbegin;
            
            headerCopy.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            
            headerCopy.Validfrom                = validfrom.dateValue(); /i fill as new value
            headerCopy.Validto                  = validfrTo.dateValue();  /i fill as new value                                    
            headerCopy.update();
            
            ttscommit;
        }
            
    }

  • waytod365 Profile Picture
    351 on at

    Thanks for your answer sir,

    Sir my scenario same like employment history  (New ) instead of (Edit ).

    I briefed small thing below.

    Old records :- 
    
    Worker | Name | No of amount | No of contract | Valid from | valid to | type
    
    000001 | Jodi | 7            | 5              | 11/05/2005 | N/A      | ticket
    
    Renew while dialog (No of contract, valid from, valid to.. only i will give you as new)
    Worker | Name | No of amount | No of contract | Valid from | valid to   | type
    
    000001 | Jodi | 7            | 3              | 08/05/2022 | 08/05/2025 | ticket

    Note : My custom details master form only (grades and grades line) two dataSource and only it has relation worker table.

    As your code caller (hcmworker) i want to grades how can i handle sir ?

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    So, your caller form is grades and that contains grades and grade lines?

    I am not clear on the exact requirement with the dialog form. Do you want to create a new record or update existing record?

  • waytod365 Profile Picture
    351 on at

    Yes sir its grades only within a form i added in action pane (Drop dialog)

    Yes its new records but only (valid from , valid to, contract no) new values another records keep it as it.

    Etc:

    Worker :- 000001 already [ contract no :- 5] [valid from :- 11/08/2206] [valid to :- Never]

    Same cursor 000001 against won't allow if its already available (error validation) these three fields only new value accept.

    Thanks

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

    So, you will need to add new records based on the existing record. Correct? If that is the case, you will need to insert new records and not update.

    Since your calling from Grades, your init method will look like this. 

    public void init()
    {
        HcmWorker   hcmWorker;
    
        if (element.args() && element.args().caller())
        {
            if (element.args().dataset() == tableNum( ))
            {
                grades      = element.args().record();
                hcmWorker   = HcmWorker::find(grades.Worker);
                
                PersonnelNumber.text(hcmWorker.PersonnelNumber);
            }
        }
    
        if (!grades)
        {
            element.lifecycleHelper().exitForm(Error::missingFormActiveBuffer(element.name(), tableStr(Grades)));
        }
    
        super();
    }

    The clicked method will look like this -

    public void clicked()
    {
        Grades                 headerCopy;
        
        ttsbegin;
        
        headerCopy.data(grades); //Will copy everything from existing record
        
        headerCopy.Validfrom        = validfrom.dateValue(); 
        headerCopy.Validto          = validTo.dateValue();
        headerCopy.ContractPeriod   = ContractPeriod.text(); // I am not sure what type of field this is. You can replace with the appropriate type.
        headerCopy.insert();
            
        ttscommit;
        
            
    }

  • waytod365 Profile Picture
    351 on at

    Thanks for your answer sir,

    But, when i click my button (drop dialog) its getting error below code.

    if (!grades)

       {

           element.lifecycleHelper().exitForm(Error::missingFormActiveBuffer(element.name(), tableStr(Grades)));

       }

    And if i comment dialog opened and personnel number not show. Also dataSet(Tablenum()) as empty you mentioned i used that place grades is that a correct if so, its not working.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 733

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 278 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans