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

HcmWorkerLookup

(0) ShareShare
ReportReport
Posted on by 95

How to restrict the HcmWorkerLookup of Sales responsible and sales Taker fields in sales order form  to workers those have sales Representative title Only

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

    Hi amr abdelaziz,

    You have to update the query in Classes\HcmWorkerLookup\updateQuery. You have to add a new global boolean variable for sales representatives and a corresponding parm method for it. You can follow the example of method "parmIncludeContractors" and write the new method similar to this method. This parm method will need to be set from lookupReference method(s) in SalesTable.

  • amr abdelaziz Profile Picture
    95 on at

    Hi Gunjan thanks for reply

    i did all thing as you talled in HcmWorkerLookup class as parmIncludeContractors

    but i don't kenw how This parm method will need to be set from lookupReference method(s) in SalesTable.

    do you means lookupReference method  in WorkerSalesResponsible field in salestable form

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

    Hi amr abdelaziz,

    Yes. I meant the same method as you mentioned. I would try something like this code to set the new parm method.

    public Common lookupReference(FormReferenceControl _formReferenceControl)
    {
        HcmWorkerLookup hcmWorkerLookup;
        
        // Commenting existing code
        //return HcmWorkerLookup::newOnlyActiveWorkers().lookupWorker(_formReferenceControl);
        
        hcmWorkerLookup = HcmWorkerLookup::newOnlyActiveWorkers();
        // Call the new parm method here
        hcmWorkerLookup.parmXXXX(true);
        
        hcmWorkerLookup.lookupWorker(_formReferenceControl);
    }

  • amr abdelaziz Profile Picture
    95 on at

    Hi Gunjan 

    What about if I add those lines in updatequery method of HcmWorkerLookup class

    QueryBuildRange titleRange;//amr
    QueryBuildDataSource qbdsWorkertitle;//amr
    qbdsWorkertitle = query.dataSourceTable(tableNum(HcmWorkerTitle));//amr titleRange = qbdsWorkertitle.findRange(fieldNum(HcmWorkerTitle, Title));//amr
    titleRange = qbdsWorkertitle.findRange(fieldNum(HcmWorkerTitle, Title));//amr
    titleRange.value(queryValue("Sales Representative" ));//amr


    but no Effect --why

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi amr abdelaziz,,

    Could you please share all the code changes you have done?

  • amr abdelaziz Profile Picture
    95 on at

    ******    I put "//amr" in the front of line added
    ********* lookupReference method in WorkerSalesResponsible field in salestable form
    public Common lookupReference(FormReferenceControl _formReferenceControl)
    {

    // Commenting existing code

    //return HcmWorkerLookup::newOnlyActiveWorkers().lookupWorker(_formReferenceControl);

    HcmWorkerLookup hcmWorkerLookup;

    hcmWorkerLookup = HcmWorkerLookup::newOnlyActiveWorkers();

    // Call the new parm method here

    hcmWorkerLookup.parmincludeRepresentatives(true);


    return hcmWorkerLookup.lookupWorker(_formReferenceControl);
    }


    ******** ClassDeclaration in HcmWorkerLookup class

    class HcmWorkerLookup
    {
    Query query;
    boolean includeEmployees;
    boolean includeContractors;
    boolean includeActive;
    boolean includePending;
    boolean includeTerminated;
    boolean includeOnlyCurrentLegalEntity;
    boolean lockWorkerTypeFilters;
    boolean lockWorkerStatusFilters;
    boolean lockLegalEntityFilters;
    boolean requireUserRelation;
    boolean enableVirtualCompany;
    boolean includeRepresentatives;                                  //AMR
    }


    ***** new pram method in HcmWorkerLookup class

    public boolean parmincludeRepresentatives(boolean _includeRepresentatives = includeRepresentatives)
    {
    includeRepresentatives = _includeRepresentatives;

    return includeRepresentatives;
    }

    ********* modification in updateQuery I put "//amr" in the front of line added
    public Query updateQuery(HcmWorkerRecId _workerRecId = 0)
    {
    QueryBuildRange legalEntityRange;
    QueryBuildRange validFromRange;
    QueryBuildRange validToRange;
    QueryBuildRange workerRange;
    QueryBuildRange workertitleRange ;                                                                  //amr
    QueryBuildRange employmentValidFromRange;
    QueryBuildRange employmentValidToRange;
    QueryBuildRange employmentTypeRange;
    QueryBuildDataSource qbdsEmployment;
    QueryBuildDataSource qbdsDirPersonUser;
    QueryBuildDataSource qbdsActiveEmployments;
    QueryBuildDataSource qbdsWorker;
    QueryBuildDataSource qbdsWorkertitle;                                                                      //amr
    utcdatetime now = DateTimeUtil::utcNow();

    qbdsWorker = query.dataSourceTable(tableNum(HcmWorker));

    qbdsEmployment = query.dataSourceName('HcmEmployment');
    qbdsActiveEmployments = query.dataSourceName('ActiveEmployments');
    qbdsDirPersonUser = query.dataSourceTable(tableNum(DirPersonUser));
    qbdsWorkertitle = query.dataSourceTable(tableNum(HcmWorkerTitle));                                                        //amr
    validFromRange = qbdsEmployment.findRange(fieldNum(HcmEmployment, ValidFrom));
    validToRange = qbdsEmployment.findRange(fieldNum(HcmEmployment, ValidTo));
    legalEntityRange = qbdsEmployment.findRange(fieldNum(HcmEmployment, LegalEntity));
    employmentTypeRange = qbdsEmployment.findRange(fieldNum(HcmEmployment, EmploymentType));
    workerRange = qbdsEmployment.findRange(fieldNum(HcmEmployment, Worker));
    workertitleRange = qbdsEmployment.findRange(fieldNum(HcmWorkerTitle, Title));                                          //amr

    employmentValidFromRange = qbdsActiveEmployments.findRange(fieldNum(HcmEmployment, ValidFrom));
    employmentValidToRange = qbdsActiveEmployments.findRange(fieldNum(HcmEmployment, ValidTo));

    // disable this query data source, and re-enable conditionally when only showing pending/terminated workers
    qbdsActiveEmployments.enabled(false);

    // disable this query data source, and re-enable conditionally only if user relation required
    qbdsDirPersonUser.enabled(false);

    if (_workerRecId != 0)
    {
    // Filter the HcmWorker table on the passed worker rec id
    workerRange.value(queryValue(_workerRecId));
    }
    else
    {
    // Include all workers
    workerRange.value(SysQuery::valueUnlimited());
    }

    if (includeOnlyCurrentLegalEntity == false
    || (_workerRecId != 0 && lockLegalEntityFilters == false))
    {
    // Include all companies
    legalEntityRange.value(SysQuery::valueUnlimited());
    }
    else
    {
    if (enableVirtualCompany && isVirtualCompany())
    {
    // Set to the virtual company list
    legalEntityRange.value(con2StrUnlimited(getVirtualCompanyList()));
    }
    else
    {
    // Limit to the current company
    legalEntityRange.value(queryValue(CompanyInfo::find().RecId));
    }
    }

    if (includeEmployees && includeContractors
    || (_workerRecId != 0 && lockWorkerTypeFilters == false))
    {
    // Do not filter by based on employee or contractor employment
    employmentTypeRange.value(SysQuery::valueUnlimited());
    }
    else if (includeEmployees)
    {
    employmentTypeRange.value(queryValue(HcmEmploymentType::Employee));
    }
    else if (includeContractors)
    {
    employmentTypeRange.value(queryValue(HcmEmploymentType::Contractor));
    }


    else if (includeRepresentatives)                                                      //amr
    {                                                                                                      //amr
    workertitleRange.value("Sales Representative");                      //amr
    }                                                                                                   //amr

    if (includeActive && includePending && includeTerminated
    || (_workerRecId != 0 && lockWorkerStatusFilters == false))
    {
    query.validTimeStateDateTimeRange(DateTimeUtil::minValue(), DateTimeUtil::maxValue());
    validFromRange.value(SysQuery::valueUnlimited());
    validToRange.value(SysQuery::valueUnlimited());
    }
    else if (includeActive && includePending)
    {
    query.validTimeStateDateTimeRange(now, DateTimeUtil::maxValue());
    validFromRange.value(SysQuery::valueUnlimited());
    validToRange.value(SysQuery::valueUnlimited());
    }
    else if (includeTerminated && includeActive)
    {
    query.validTimeStateDateTimeRange(DateTimeUtil::minValue(), now);
    validFromRange.value(SysQuery::valueUnlimited());
    validToRange.value(SysQuery::valueUnlimited());
    }
    else if (includeActive)
    {
    query.validTimeStateDateTimeRange(now, now);
    validFromRange.value(SysQuery::valueUnlimited());
    validToRange.value(SysQuery::valueUnlimited());
    }
    else if (includeTerminated)
    {
    query.validTimeStateDateTimeRange(DateTimeUtil::minValue(), DateTimeUtil::utcNow());
    validFromRange.value(SysQuery::valueUnlimited());
    validToRange.value(SysQueryRangeUtil::lessThanUtcNow());

    // don't include active employments
    employmentValidFromRange.value(SysQueryRangeUtil::lessThanUtcNow());
    employmentValidToRange.value(SysQueryRangeUtil::greaterThanUtcNow());
    qbdsActiveEmployments.enabled(true);
    }
    else if (includePending)
    {
    query.validTimeStateDateTimeRange(HcmDateTimeUtil::startOfCurrentDay(), DateTimeUtil::maxValue());
    validFromRange.value(SysQueryRangeUtil::greaterThanUtcNow());
    validToRange.value(SysQuery::valueUnlimited());

    // don't include active employments
    employmentValidFromRange.value(SysQueryRangeUtil::lessThanUtcNow());
    employmentValidToRange.value(SysQueryRangeUtil::greaterThanUtcNow());
    qbdsActiveEmployments.enabled(true);
    }

    if (requireUserRelation)
    {
    qbdsDirPersonUser.enabled(true);
    }

    return query;
    }

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

    Hi amr abdelaziz,

    The table HcmWorkerTitle is not included in the query HcmWorkerLookup. You will need to add the tables HcmWorkerTitle and HcmTitle to this query. The table HcmWorkerTitle will joined to HcmWorker. HcmTitle will need to be linked to HcmWorkerTitle. You can create a range on HcmTitle\TitleId field and set this range.

  • amr abdelaziz Profile Picture
    95 on at

    Hi Gunjan Bhattacharyya
    thank you it's ok now

    if (includeRepresentatives)
    {
    qbdsWorkertitle = qbdsWorker.addDataSource(tableNum(HcmWorkerTitle));
    qbdsWorkertitle.relations(false);
    qbdsWorkertitle.addLink(fieldNum(HcmWorker,RecId),fieldNum(HcmWorkerTitle,worker));
    qbdsWorkertitle.joinMode(JoinMode::InnerJoin);
    qbdstitle = qbdsWorkertitle.addDataSource(tableNum(HcmTitle));
    qbdstitle.relations(false);
    qbdstitle.addLink(fieldNum(HcmWorkerTitle,title),fieldNum(HcmTitle,RecId));
    qbdstitle.joinMode(JoinMode::InnerJoin);
    titleRange = qbdstitle.addRange(fieldnum(HcmTitle,titleid));
    titleRange.value('Sales Representative');
    }

    put how to take the parameter from the Hcmworkerlooup form like includeContractors

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