- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:34 AM - edited 05-31-2023 02:38 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:56 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 02:56 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 03:13 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 03:46 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 03:48 AM
Thanks Karan