How to prevent updating the change value from Software Model to Software Catalog

nguyennguyent
Tera Contributor

Hello everyone,

I have one issue on ServiceNow.

Currently I'm performing one Business Rule that required not be allowed sync new data on one field from Software Model to Software Catalog.

Specifically as follow: When I change value on Model Number field of table Software Model, I want that new value not sync to Software Catalog, it means respective field on Software Catalog table still keep old value.

Ex: Model Number field has attribute name is model_number in Software Model

      and is product_id in Software Catalog (they correspond to each other)

But Model Number field in Software Catalog still save new value when changing value from Software Model.

 

Please help me this issue. Thanks!

 

Specs:

When to run: After - Update

Parent table: [cmdb_software_product_model]
Child table: [pc_software_cat_item]

My coding:

(function executeRule(current, previous /*null when async*/) {
     if(current.sys_class_name == 'cmdb_software_product_model') {
          var chil = new GlideRecord("pc_software_cat_item");
          chil.addQuery('parent', current.sys_id);
          chil.addQuery('product_id', current.model_number);
          chil.query();
          while(chil.next()) {
               current.setAbortAction(true);
               current.update();          }
     }

})(current, previous);

 

model_number field.jpgproduct_id field.jpg


Tuan

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

@nguyennguyent The product ID is synced OOB, but you can handle it from a before update BR on "pc_sofware_cat_item" with condition "product id changes and product id is not empty", with below code:

 

current.product_id = previous.product_id;


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

View solution in original post

3 REPLIES 3

RaghavSh
Kilo Patron

@nguyennguyent The product ID is synced OOB, but you can handle it from a before update BR on "pc_sofware_cat_item" with condition "product id changes and product id is not empty", with below code:

 

current.product_id = previous.product_id;


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

Hi @RaghavSh 

Wonderful. You're expert! Thanks a lot!
When I created other BR and with conditions that you suggested, it works fine 😊

It's good to be able to handle in a single BR. 

@nguyennguyent glad that worked!!!


Raghav
MVP 2023