Mark the old duplicate cases state ="canceled"

Insider
Giga Guru

Hello.

I am creating a new record using Flow.

-> When this record is created it should check the record table and mark duplicate cases as "canceled" where we should check both duplicate product_code and customer_code fields on the records.

 

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

@Insider ,
I trust you are doing great.
You can try something like this

// This is a conceptual script to be adapted in the Flow Designer

// Assuming 'current' is the newly created record
var productCode = current.product_code;
var customerCode = current.customer_code;

// Lookup duplicate records
var dupRecord = new GlideRecord('your_table_name'); // Replace with your table name
dupRecord.addQuery('product_code', productCode);
dupRecord.addQuery('customer_code', customerCode);
dupRecord.addQuery('sys_id', '!=', current.sys_id); // To exclude the current record
dupRecord.query();

while (dupRecord.next()) {
    // Mark each duplicate record as canceled
    dupRecord.state = 'canceled'; // Replace 'state' with your field name for record status
    dupRecord.update();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Insider 

 

I am not sure, I understood your requirement fully or not

 

-> When this record is created it should check the record table and mark duplicate cases as "canceled" where we should check both duplicate product_code and customer_code fields on the records.

Atul: Also add state is not closed or cancelled , so that the check can be done only for active cases not the closed one. 

 

Also what issue you are facing in this? Any screen shot?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

I was able to cancel the duplicate records using Before BR.

Along with state=cancel, i should also be able to change the date field to "Current date, time" which i ma trying on BR but its not working.

I am using:

 while (gr1._next()) {
                var now = new GlideDateTime();
                gr1.status = 'Rejected';
                gr1.expiration_date = now.getDisplayValue();
                gr1.update();

Amit Gujarathi
Giga Sage
Giga Sage

@Insider ,
I trust you are doing great.
You can try something like this

// This is a conceptual script to be adapted in the Flow Designer

// Assuming 'current' is the newly created record
var productCode = current.product_code;
var customerCode = current.customer_code;

// Lookup duplicate records
var dupRecord = new GlideRecord('your_table_name'); // Replace with your table name
dupRecord.addQuery('product_code', productCode);
dupRecord.addQuery('customer_code', customerCode);
dupRecord.addQuery('sys_id', '!=', current.sys_id); // To exclude the current record
dupRecord.query();

while (dupRecord.next()) {
    // Mark each duplicate record as canceled
    dupRecord.state = 'canceled'; // Replace 'state' with your field name for record status
    dupRecord.update();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



This worked great amit. But i am not able to populate the comments on this record.
I need to populate comments as " Auto-Cancelled due to approval of new case + <case Number of the new case record >"