Wednesday, 11 July 2018

How to Use LIKE Operator in select Query X++

It is very common to use Like Operator in SQL 

SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;

Now we will see how we can use the Like operator in X++

It is very similar to SQL as shown in the below example. In this example, I'm updating  TrvPartyEmployeeRelationship with HcmWorker table.


static void MK_TrvPartyEmpUpd(Args _args)
{
    DataArea    dataArea;
    TrvPartyEmployeeRelationship    empRelation;
    HcmWorker                       worker;
    HcmPersonnelNumberId            empName;
    while select dataArea
        where dataArea.isVirtual == NoYes::No
    {
        changeCompany(dataArea.id)
        {
            empRelation = null;
            while select forUpdate empRelation
            {
                worker = null;
                empName = "";
                empName = strFmt("%1%2%3","*",empRelation.DEL_EmplId,"*");
                select firstOnly worker 
                where worker.PersonnelNumber like empName;
                if (worker.RecId)
                {
                    ttsBegin;
                    empRelation.selectForUpdate(true);
                    empRelation.Worker = worker.RecId;
                    empRelation.doDelete();
                    ttsCommit;
                    
                }
            }
            
        }
    }
}

No comments:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...