Glide Record on to two table is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 09:58 AM
Hi All,
I had a requirement to find if there is any match of product in the custom software product table to the software Model table. If there is no match found then de active the custom software product.
I have written a fix script but it is not updating, not sure where i am missing the logic.
var sp=new GlideRecord("samp_custom_sw_product");
sp.addEncodedQuery("active=true");
sp.query();
while(sp.next())
{
var sm=new GlideRecord("cmdb_software_product_model");
sm.addQuery('product',sp.prod_name);
sm.query();
if(!sm.next())
{
sw.active=false;
sw.setWorkflow(false);
sw.update();
gs.log("prod name :"+sp.prod_name);
}
}
Anyone can please help me on this,
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 10:09 AM
Hi Sangeetha,
Script seems fine. Can you ensure field names are correctly used. Additionally, try adding logs to the script of script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 10:11 AM - edited 06-28-2024 10:13 AM
Hi @Community Alums,
The issue I see or the question I'm asking myself is what are the sw. referring to?
sw.active=false;
sw.setWorkflow(false);
sw.update();
Should these not read:
sp.active=false;
sp.setWorkflow(false);
sp.update();
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
Final full script:
var sp=new GlideRecord("samp_custom_sw_product");
sp.addEncodedQuery("active=true");
sp.query();
while(sp.next())
{
var sm=new GlideRecord("cmdb_software_product_model");
sm.addQuery('product',sp.prod_name);
sm.query();
if(!sm.next())
{
sp.active=false;
sp.setWorkflow(false);
sp.update();
gs.log("prod name :"+sp.prod_name);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 10:26 AM
Hi @Robbie ,I did the changes as per your script,but it is returning all the custom product,I need to deactive only the not matched product
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2024 10:38 AM
Hi @Community Alums,
Let me clarify my understanding here. You want to loop through all of the active records on the 'samp_custom_sw_product' table, and IF this record does NOT match a record in the 'cmdb_software_product_model' table, deactivate it. Correct?
Why don't you comment out the .update line or run this as a background script first to check numbers before executing.
Try this by navigating to "Background - Script" and running to confirm numbers:
var customSW_count = 0;
var cmdbSW_count = 0;
var sp=new GlideRecord("samp_custom_sw_product");
sp.addEncodedQuery("active=true");
sp.query();
while(sp.next())
{
customSW_count ++; // This will give you the count of active samp_custom_sw_product records it's looping through
var sm=new GlideRecord("cmdb_software_product_model");
sm.addQuery('product',sp.prod_name);
sm.query();
if(!sm.next())
{
sp.active=false;
sp.setWorkflow(false);
//sp.update();
gs.log("prod name :"+sp.prod_name);
cmdbSW_count ++ // This will give you the count of where there is no match
}
}
gs.print('customSW_count : ' + customSW_count);
gs.print('cmdbSW_count : ' + cmdbSW_count);
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie