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

Condition Str2Int and str2Enum in x++

(0) ShareShare
ReportReport
Posted on by 1,215

Hi all,

Scenario : while an importing i want to "employment type" in excel column.

if user give it to '0' "employment type should be updated in "Employee"

if user give it to "Employee" should be updated in  "Employee"

if user wrongly mentioned Employment type (3, or something) i want to throw error if employment type not in........""

below my code.

 if(hcmEmployment.RecId)
{
ttsbegin;
hcmEmployment.selectForUpdate(true);
hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmployment.EmploymentType = str2Enum(employmentType, range.get_Item(rowNo,6).Value);
//condition //hcmEmployment.EmploymentType = str2int(employmentType, range.get_Item(rowNo,6).Value) ?str2Enum(employmentType, range.get_Item(rowNo,6).Value) : "";
hcmEmployment.doUpdate();
ttscommit;
}

Thanks 

I have the same question (0)
  • Verified answer
    ergun sahin Profile Picture
    8,826 Moderator on at

    I did not fully understand what you wanted to do, but it seemed like you can solve it by simplifying it a little bit as follows.

    str             strEmploymentType;
    EmploymentType  employmentType;
    ;
    strEmploymentType = range.get_Item(rowNo,6).Value;
    
    if(strEmploymentType == "0" || strEmploymentType == "Employee")
    {
        employmentType = EmploymentType::Employee;
    }
    else if(strEmploymentType == "1" || strEmploymentType == "Contractor")
    {
        employmentType = EmploymentType::Contractor;
    }
    else
    {
        throw error("");
    }
    
    if(hcmEmployment.RecId)
    {
        ttsbegin;
        hcmEmployment.selectForUpdate(true);
        hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
        hcmEmployment.EmploymentType = employmentType;
        hcmEmployment.doUpdate();
        ttscommit;
    }

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your answer mr,Ergun Sahin,

    same I'm expecting, but am getting an one error "strEmploymentType == 1"  

    errror: operator == cannot be applied to operands of types "str: to" int"

  • ergun sahin Profile Picture
    8,826 Moderator on at

    I guess you solved the error in the code but still wanted to fix it

    strEmploymentType == "1"

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans