CI should not create with lifecycle status "End of life", but it should update if status is changing

GautamiK
Tera Contributor

I am loading the data using Robert Transform Map in CMDB, requirement is that if the Lifecycle status is "End of Life", CI record should not create. And if there is an existing CI record with different status, and if in source status is changing to "End of Life", the CI record should update. I have written the below script, it working for creation part, but not working for Update. Can anyone help?

 

(function onBefore(source, target, importLog) {

    var lifecycleStatus = source.u_life_cycle_stage;

 

    // If the record is new and status is "End of Life", skip creation

    if (!target.isValidRecord() && lifecycleStatus == "End of Life") {

        ignore = true;

        return;

    }

 

    // If updating and status is "End of Life", update the field if it's different

    if (target.isValidRecord() && lifecycleStatus == "End of Life") {

        if (target.life_cycle_stage != lifecycleStatus) {

            target.life_cycle_stage = lifecycleStatus;

        } else {

            ignore = true;

        }

    }

})(source, target, importLog);

1 REPLY 1

Sandeep90
ServiceNow Employee
ServiceNow Employee

One simple solution would be to just add an insert BR to abort CI creation if Life Cycle Status is "End of Life". For update you don't have to do anything as it will be handled automatically.