Concurrency on Records

ShivangiC
Tera Contributor

My requirement is:-

Employee submits an expense record via record producer and his Manager is asked for approval. I want to implement if Manager has opened an Expense Record[on platform UI or from My Tasks in Esc portal ] for approval and the same record or its related line items[another table] is being modified by the Employee at the same time. As soon as Employee updates the record of which approval is opened by the Manager on his screen, a confirm dialog box must appear for the Manager and after confirm dialog box the page must refresh in ServiceNow.

 

Please help me out with this solution

14 REPLIES 14

Mark Manders
Mega Patron

You have responded to us by telling us the same thing 6 (!) times. My solution will prevent approval on changed records. I don't see anything in your responses why that wouldn't work. You are providing a bad solution for an issue that, most likely, will rarely happen (I fully agree with Ankur's response, but decided to help you anyway). 

 

You should prevent it all together, not create some client side solution that will probably also fail. In fact: why would you even allow the employee to change anything after asking for approval? I am now thinking that the best solution all together is to make it read only with a button that does 2 things whin clicked: it takes the record from read only AND it cancels the approval record. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

But what if Manager has entered some remarks in the previous Approval record without even Approving or Rejecting the record...how can we bring them on the new approval generated after modifying the record?

The previous approval is no longer a valid approval. If the user changes anything, it should be a new approval on the new information. Comments on a previous approval are related to different information, so do not relate to the new expense report.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

You only help me out with the implementation of your solution i.e. generating second approval should I do it with Flow designer. Just write pseudo code or algorithm or steps. How should I proceed?

ShivangiC
Tera Contributor

@Mark Manders  and @Ankur Bawiskar please help me with Business rule in order to implement if Expense record is modified before Approval or Rejection, the existing record in Approval table must be set with State-> No longer Required and then my Flow Designer flow must restart. Currently this is my Business Rule script:-

(function executeRule(current, previous /*null when async*/) {

    // 1. Cancel existing approvals
    var approvalGR = new GlideRecord('sysapproval_approver');
    approvalGR.addQuery('sysapproval', current.sys_id);
       
        while (approvalGR.next()) {
            approvalGR.state = 'not_required';
            approvalGR.update();
        }

        // 2. Restart Flow Designer flow
        if (current.flow_context) {
            try {
                sn_fd.FlowAPI.restartFlow(current.flow_context);
                gs.info('Flow restarted for record: ' + current.number);
            } catch (e) {
                gs.error('Error restarting flow: ' + e);
            }
        } else {
            gs.warn('No active flow context found for record: ' + current.number);
        }

})(current, previous);
 
This is an After Update BR with conditions:- when 'Updates' changes and 'Approval Status' is 'Requested'.