Unable to set default value of True/False field

Sachin G K1
Kilo Sage

Hi All,

 

How to set default value of True/False field to True, i used configure dictionary but it works on only new catalog item, not existing ones!!

 

 

 

Thanks in Advance,

Sachin

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Sachin G K1 ,

 

The default value won't reflect on the records which were created prior, for old records, you need to create a fix script and then update the checkbox there, refer to the below fix script and replace the variable name, I've used 'Hide Delivery Time' field as an example, please add more filter conditions according to the requirement

This script would update all the records where the checkbox is false, add some filter conditions

updateCatItems();
function updateCatItems() {

    var catalogGR = new GlideRecord('sc_cat_item');
    catalogGR.addActiveQuery();
    catalogGR.addQuery('no_delivery_time_v2', 'false');
    catalogGR.query();
    while (catalogGR.next()) {

        catalogGR.setValue('no_delivery_time_v2', 'true');
        catalogGR.setWorkflow(false);
        catalogGR.autoSysFields(false);
        catalogGR.update();
    }

}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

 

 

 

View solution in original post

4 REPLIES 4

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Sachin G K1 ,

 

The default value won't reflect on the records which were created prior, for old records, you need to create a fix script and then update the checkbox there, refer to the below fix script and replace the variable name, I've used 'Hide Delivery Time' field as an example, please add more filter conditions according to the requirement

This script would update all the records where the checkbox is false, add some filter conditions

updateCatItems();
function updateCatItems() {

    var catalogGR = new GlideRecord('sc_cat_item');
    catalogGR.addActiveQuery();
    catalogGR.addQuery('no_delivery_time_v2', 'false');
    catalogGR.query();
    while (catalogGR.next()) {

        catalogGR.setValue('no_delivery_time_v2', 'true');
        catalogGR.setWorkflow(false);
        catalogGR.autoSysFields(false);
        catalogGR.update();
    }

}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

 

 

 

Hi Karan,

 

Above script is working great, just i am curious to why below lines of code written, what it actually does?

 

catalogGR.setWorkflow(false);

catalogGR.autoSysFields(false);

 

 

@Sachin G K1  - setWorkflow(flase) prevents all the business rules and workdflows from running which would usually execute if we were to update the record manually or without using setWorkflow(false)

 

autoSysFields(false) makes sure that the system fields such as updated by, updated on are not changed once the records are updated via the fix/background script 

Thanks Karan