- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 10:18 PM
The requirement is to update the "managed by" and "owned by" fields for existing hardware records, to correct for empty fields and records where the owner or manager is no longer with the company. Also, records with RETIRED state need not be altered.
My BR for new records:
getFields();
function getFields(){
var data = new GlideRecord('ci_data_lookup');
data.addQuery('active','true');
data.addQuery('ci_class',current.model_category.cmdb_ci_class);
data.query();
//gs.addInfoMessage(data.getRowCount());
while(data.next()){
current.managed_by = data.u_managed_by;
current.owned_by = data.u_owned_by;
current.u_managed_company = data.u_managed_company;
current.update();
}
}
BR would run and work for new records.
How and what can I do to update the existing records?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 12:07 AM
Hi @nitinsharma2510 ,
I did the below changes in code and it worked perfectly fine.
var data = new GlideRecord('alm_hardware');
data.addEncodedQuery('install_status!=7^ORinstall_status=NULL');
//data.setLimit(2);
data.query();
while(data.next()){
var lookupData = new GlideRecord('ci_data_lookup');
lookupData.addActiveQuery();
lookupData.addQuery('ci_class',data.model_category.cmdb_ci_class);
lookupData.query();
if(lookupData.next()){
data.managed_by = lookupData.u_managed_by;
data.owned_by = lookupData.u_owned_by;
data.u_managed_company = lookupData.u_managed_company;
data.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2023 09:50 PM
@nitinsharma2510 , Also, records with RETIRED state need not be altered. Is this something that we can add in builder?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 12:17 AM
@Swetha M you can change the condition to
data.addEncodedQuery('active=true^install_status!=7^managed_by.active=false^ORowned_by.active=false^ORu_managed_company.active=false^ORowned_byISEMPTY^ORmanaged_byISEMPTY^ORu_managed_companyISEMPTY');
'install_status' is the backend name for the State field and 7 is the choice value for retired state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 12:07 AM
Hi @nitinsharma2510 ,
I did the below changes in code and it worked perfectly fine.
var data = new GlideRecord('alm_hardware');
data.addEncodedQuery('install_status!=7^ORinstall_status=NULL');
//data.setLimit(2);
data.query();
while(data.next()){
var lookupData = new GlideRecord('ci_data_lookup');
lookupData.addActiveQuery();
lookupData.addQuery('ci_class',data.model_category.cmdb_ci_class);
lookupData.query();
if(lookupData.next()){
data.managed_by = lookupData.u_managed_by;
data.owned_by = lookupData.u_owned_by;
data.u_managed_company = lookupData.u_managed_company;
data.update();
}
}