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, ...
Answered

Different companies validation need to check

(0) ShareShare
ReportReport
Posted on by 351

Hi all,

I add it hcmemployment history form one field and that field I want to update so that below condition need it.

I.e ;- If the worker has  3 company and current legal entity is not active then i want error message.( Current legal entity active then update)

If the worker has two company and not in current legal entity and other company if its active then update that field.

Only if there is three company and not in current legal entity active then validation message i want.

Hcmemployment:;Isactive(hcmEml.recid) 

How can I check about i mentioned condition?

Thanks 

I have the same question (0)
  • Suggested answer
    nunomaia Profile Picture
    25 Moderator on at

    In Select , you can use the crossCompany keyword to query data from multiple companies

      select
                crossCompany
                * from workerTable

    You can also change company in code by using changecompany keyword 

    changeCompany('XXXX') 
    {
        Hcmemployment:;Isactive(hcmEml.recid)      
    }

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

    Hi Waytod365,

    I'm not able to understand the business requirement. What is the field about and why do you need to change data on a history form? What do you mean with an active legal entity?

  • waytod365 Profile Picture
    351 on at

    Thanks for your replay Nuno Maia,

    Actually i want to 

    Active employment > 1 and current legal is not active Give message can't update ,employee has 3 legal entitles active employment

    Active employment = 1 and current legal is not active , update the active one.

    Note : active means "valid from" today date only here.

    Code : -

    employment = HcmEmployment::getActiveEmploymentsByWorker(worker.RecId);
    HcmEmployment emp =  HcmEmployment::getActiveEmploymentsByOtherLegalEntity(worker.RecId); //getActiveEmploymentsByWorker same method i used with an extension ie. && hcmEmployment.LegalEntity !=  CompanyInfo::find().RecId; 
    
    if(employment.RecId)
    {
    ttsbegin;
    employment.selectForUpdate(true);
    employment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
    if(employment.ValidTo && emp.LegalEntity >2)
    {
        warning("can't update ,employee has 3 legal entitles active employment");
    }
    else
    {
        employment.CountryLE = CustomFields; // already has record
    }
    employment.doUpdate();
    ttscommit;
    }

    But above code is not working how can i check if has 3 legal entity with active ?

    Thanks 

  • GirishS Profile Picture
    27,827 Moderator on at

    Hi waytod365,

    Since HcmEmployment is a global table you can directly get the count from table against that worker.

    Select count(RecId) from employment
        where employment.worker == worker.RecId;
        
    if(Int642int(employment.RecId) >= 3)
    {
        //warning
    }
    else
    {
        //update
    }

    Thanks,

    Girish S.

  • waytod365 Profile Picture
    351 on at

    Thanks for your answer Girish S.,

    I want to in the else part if its other legal entity has active employment.

    Like : USSI, DAT in this case USSI active i wanna update USSI only.

    Another condition : If its current legal entity USMF , USSI, DAT

    in this case i wanna update only USMF (If its USMF inactive error i want 3 has legal entity)

    I need it 3 condition so that how can i do that please give me a example on this.

  • GirishS Profile Picture
    27,827 Moderator on at

    Its little bit confusing. Can you elaborate more by listing down the scenarios.

    Thanks,

    Girish S.

  • waytod365 Profile Picture
    351 on at

    Thanks Girish S.,

    The thing is i want to check three condition.

    1. If the worker has two more company and current legal is not active. in this case i wanna validation

    Note : Three company but current legal entity has active then update only USMF otherwise validation need.

    2. If the worker has another legal entity like : USSI, DAT.

    Note:  If the USSI has active employment then update only USSI enough.

    As i mentioned above is my scenario. hope is it clear now.  

    Thanks

  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    HcmEmployment employmentCount, employment;
    CompanyInfo  compInfo;
    
    //check if the worker is active in current legal entity
    Select * from employment
        where employment.worker == worker.RecId
        join compInfo
        Where compInfo.RecId == employment.LegalEntity
        && compInfo.DataArea == curExt();
    
    //get the total active employment for the worker.
    Select count(RecId) from employmentCount
        where employmentCount.worker == worker.RecId;
     
    //if active emploment greater then or equal to 3 and doesnt have active employment in current 
    // legal entity throw validation
    if(Int642int(employmentCount.RecId) >= 3 && !emploment)
    {
        //warning
    }
    else if(emplyoment)
    {
        //update the record
    }

    So the worker is active in more than one company and he doesn't have active employment in current company  - Throw validations.

    If the worker is active in current company - update it.

    Thanks,

    Girish S.

  • waytod365 Profile Picture
    351 on at

    Sorry for late replay GirishS,

    As you mentioned above code is works good, but one condition only its not work.

    Etc: If the worker has : USSI, DAT has active employment in this case its not updated.

    I want to update.

    Thanks

  • GirishS Profile Picture
    27,827 Moderator on at

    In that case you can add another select statement to employment table without adding the company info in where condition.

    HcmEmployment employmentCount, employment,employmentAll;
    CompanyInfo  compInfo;
    
    //check if the worker is active in current legal entity
    Select * from employment
        where employment.worker == worker.RecId
        join compInfo
        Where compInfo.RecId == employment.LegalEntity
        && compInfo.DataArea == curExt();
        
    //active workers across all companies.
    Select * from employmentAll
        where employmentAll.worker == worker.RecId;
        
    
    //get the total active employment for the worker.
    Select count(RecId) from employmentCount
        where employmentCount.worker == worker.RecId;
     
    //if active emploment greater then or equal to 3 and doesnt have active employment in current 
    // legal entity throw validation
    if(Int642int(employmentCount.RecId) >= 3 && !emploment)
    {
        //warning
    }
    else if(emplyoment || employmentAll)
    {
        //update the record
    }

    Thanks,

    Girish S

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans