✏️ Explanatory Question

Example of using Query::update_recordset in D365FO

👁 0 Views
📘 Detailed Answer
🟢 Easy
0
Total Views
4
Related Qs
0%
Progress
💡

Answer with Explanation


Public class ReqItemTableUpdService extends SysOperationServiceBase
{
public void run(ReqItemTableUpdContract _contract)
{
ReqItemTable reqItemTable;
QueryRun queryRun;

    Map                         fieldMapping        = new Map(Types::String, Types::String);
    Query                       query               = new Query(SysOperationHelper::base64Decode(_contract.parmPackedQuery()));
 
    NoYesId                        reqPOTypeActive     = _contract.parmReqPOTypeActive();
    ReqPOType                   reqPOType           = _contract.parmReqPOType();
    InventLocationIdReqMain     inventLocationId    = _contract.parmInventLocationId();
    #OCCRetryCount
 
    fieldMapping.insert(fieldStr(ReqItemTable, ReqPOTypeActive), any2Str(reqPOTypeActive));
    fieldMapping.insert(fieldStr(ReqItemTable, ReqPOType), any2Str(reqPOType));
    fieldMapping.insert(fieldStr(ReqItemTable, InventLocationIdReqMain), any2Str(inventLocationId));
 
    try
    {
        ttsbegin;
        Query::update_recordset(fieldMapping, query, true, true, true);
        tommit;
 
        info("Item coverage details updated successfully.");
    }
    catch (Exception::Deadlock)
    {
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw exception::UpdateConflict;
        }
    }
}
}