How to prevent the state of a case from reverting to "New" after being set to "Open"

is_12
Tera Contributor

Hello Community,

 

When the request is created from the case in workspace/native UI, then the state of the case should not move back to New. How to prevent this.

 

Requirement : when state of existing request is moved to work in progress  then state of case is moved from new to open ( functionality is already there). When one more request is created for the same case then state of case is moving back to new. Ideally it should be in the open only How to restrict it

 

There is already one BEFORE BR on sc_request for state sync.

 

Tried this way 

if (current.state == 1 && b2bCase.state == 10) {
current.setAbortAction(true);
return;
}

but for the second time request is not getting created.

Thanks,

 

 

7 REPLIES 7

@is_12 

I doubt then it can be achieved.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar can we check the request created time difference & then set the state 

 

is_12
Tera Contributor

@Ankur Bawiskar 

 var createdDate = new GlideDateTime(current.sys_created_on);
        var currentDate = new GlideDateTime();
        var timeDifference = GlideDateTime.subtract(currentDate, createdDate).getNumericValue();

        //var timeDifferenceInMilliseconds = timeDifference.getDurationValue();
        var timeDifferenceInSeconds =  timeDifference / 1000;

        gs.info('IshTimeBR17 ' + timeDifference);
        gs.info("IshTimeBR18 created " + createdDate);
        gs.info("IshTimeBR19 current " + currentDate);

        if (timeDifferenceInSeconds > 0) {
            gs.info("IshTimeBR22 diffirence " + timeDifferenceInSeconds);

        } else if (current.state == 1) {
            gs.info('IshTimeBR25 ' + b2bCase.state);
            // Req state Open
            b2bCase.setValue('state', 1); // B2b Technical Support Case State to New
            b2bCase.update();
 
getting logs still 19 but it is not entering the if block
 
ideally if the request is there then it should go to if block 
but else part is getting executed and again state is setting to new