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

Regarding Valid from in D365Fo

(0) ShareShare
ReportReport
Posted on by 351

Hi,

I want to while import if 'Valid from' and 'valid to' empty in excel.

I want to pick employment start date worker against same like also 'valid from'(max date).

Example:

My excel:-

[Worker no [valid from [Valid to

000020      [Null [Null

Once i import above excel i want to based on 20 against start date so that how to do in x ?

Below my code.

Note : toInsert is my custom table and has it relation in HcmWorker.

if(str2Date(range.get_Item(rowNo,2).Text, 123) == dateNull())
{
    toinsert.ValidFrom = //Here is how can i achive it ?
}
if(str2Date(range.get_Item(rowNo,3).Text, 123) == dateNull())
{
    toinsert.Validto = DateTimeUtil::maxValue(); // Max date is correct ?
}

Thanks 

 

I have the same question (0)
  • waytod365 Profile Picture
    351 on at

    Correction : *same like also 'valid to'

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at

    Hi,

    So, if I understand correctly, you want to assign the Employment start date from the Worker to your Valid from field, right?

    If that's the ask, then you can use Worker # in order to get Employee start date:

    select HcmEmployment
    join hcmWorker
    where hcmWorker.RecId == HcmEmployment.Worker
    && hcmWorker.RecId == workerNbr //000020 worker you mentioned

    And then assign HcmEmployment.ValidFrom to your table field.

    Let me know if that answers your question.

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi waytod365,

    What exact date value do you want to use for the ValidFrom field? If you need an "empty" date, you can use DateTimeUtil::minValue().

  • waytod365 Profile Picture
    351 on at

    Thanks for your replay mr.Danilo Bambi ,

    I will tell you what i want exactly in Excel.

    I have an one custom form.

    3515.Empl1.PNG

    As shown in the picture above, there is Worker no : 000001 against Valid from : 2/1/2006.

    The standard HcmWorker form. 

    Worker no : 000001 against in the Employment history valid from  2/1/2006.

    Note : in my custom form i did it manual entry.

    The same process while import in excel and 'valid from' and 'valid to'  null in excel column based on a worker against in the employment valid from date insert in my custom form valid from.

    Now, i will go to import worker no :000011 in Employment history  valid from (8/5/2009 12:00:00 AM)

    The same valid from while import if valid from null same date i want.

    My excel column:

    5516.Excel.PNG

    Valid from , valid to is empty once imported 000011 record.

    Then i will go to check my custom form. there is worker against in the emmployment history same to date insert or not.

    So that how to write in x++ give me example for that.

    Thanks for your attention.

  • Suggested answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    Danino's approach is correct, only if I'm not mistaken, the same worker can have multiple records, you need to look at the active record. Or you can use the table's own method directly.

    if(str2Date(range.get_Item(rowNo,2).Text, 123) == dateNull())
    {
        toinsert.ValidFrom = HcmEmployment::getActiveEmploymentsByWorker(HcmWorker::findByPersonnelNumber("000020").RecId).ValidFrom;//Here is how can i achive it ?
    }
    if(str2Date(range.get_Item(rowNo,3).Text, 123) == dateNull())
    {
        toinsert.Validto = DateTimeUtil::maxValue(); // Max date is correct ?
    }

  • waytod365 Profile Picture
    351 on at

    Sorry for the late replay sir,

    I hope you'll be well and i remember in prayer turkey.

    Thanks for your suggestion.

    I noted 'valid from' and 'valid to'  is mandatory in my table so that I changed little bit.

    While import dialogue add new check box pick from employment if it’s = 'yes '

    This check box valid for contract status.

    How to do in if its 'yes' ?

    thanks a lot for your time beforehand.

  • waytod365 Profile Picture
    351 on at

    Sir,

    I want to only contract status in check box so that i wrote a one code.

    public boolean Fld2_1_modified()
        {
            FormComboBoxControl control = dialog.formRun().controlCallingMethod();
            boolean isEmployments;
    
            isEmployments = control.modified();
    
            if(isEmployments)
            {
                dialogEmployment.value(NoYes::No);
                if(control.selection())
                {
                    if(importTypes == ImportType::Contracts)
                    {
                        dialogEmployment.visible(true);
                    }
                }
                
    
            }
    
            return isEmployments;
        }

    As i mentioned above code i did it also getFromDialog()

    ImportType = dialogImport.value();

    But that modified not worker what am i missing ?

    2. Once in the contract status and check box Yes.

    Run method.

     if (importTypes == ImportType::Contract)
     {
        if(IsEmployment.value() ==  noyes::Yes)
        {
            toInsert.validFrom = HcmEmployment::getActiveEmploymentsByWorker(HcmWorker::findByPersonnelNumber("000011").RecId).ValidFrom;
            toInsert.ValidTo = DateTimeUtil::MaxDate();
            ToInsert.Insert();
        }
     }
     
     //I'm wondering we need to insert (toinsert.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);)
     or only update ?

    The second approach is correct ? let me know sir if anything missing.

  • waytod365 Profile Picture
    351 on at

    Correction : Not working* in modified.

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    I'm getting lost here. Your question was about getting a date from the employment. Now you are mixing up the question with a dialog issue. Can you let us know if the From date issue is solved?

    Please create a new question if you have issues with a dialog.

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