How to delete all records which i have loaded through import sets to hardware table.

Chaitanya Redd1
Tera Guru

Hello Team,

I/'m trying to delete all the records which I have loaded using import set. i'm trying to delete manually but some how few records are still showing up when I click on that records it's showing record not found. 

Can anyone help me to delete all the records using any script.

 

Thanks,

JRY

1 ACCEPTED SOLUTION

DirkRedeker
Mega Sage
Hi It looks as if you put in a class value in your transform script that is invalid. Can you share a screenshot of ghd ghost records list including the "class" column? Can you change the value of the class field manually and delete the records afterwards? Let me know if that answered your question and mark my answer as correct and helpful BR Dirk

View solution in original post

17 REPLIES 17

johnfeist
Mega Sage
Mega Sage

Hi Jry,

You can do what you need via a glide record as follows:

var theRecords = new GlideRecord("<your table name>");
theRecords.addQuery(<addd the criteria to isolate your records>);
theRecords.Query();
var theRecordsCount = theRecords.getRowCount();
gs.addInfoMessage("Retrieved " + theRecordsCount +" rows");
return;
theRecords.deleteMultiple();

I set this up so that when you first run this, you can confirm that the right number of records are being captured.  Once you are satisfied that all the records you need to delete, and only those, are being captured in the query, you can take out the return statement.

You will need to include as many theRecords.addQuery() (or similar) statements to assure that you can properly specify your needed records.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

I tried it but not working still I can see ghost records which are there in hardware asset list when I clicking on the any records it's showing record not found

Please provide more information, e.g. screen prints including your criteria and resulting records that are not being removed.

You may also need to see if there are security or similar constraints that are preventing you from accessing those records.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

can you please go through with above screen prints in that last screenshot you can see that records are not getting deleted and  

 

find_real_file.png

i need one more i'm trying to computer set the class in the import set tables,so all the assets are just created in the cmdb_ci table instead of the sys_name_class. for that i have written below script 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
 target.sys_class_name = "cmdb_ci_computer";
})(source, map, log, target);
 
 
 
it's setting in correct ci but when i'm looking to records it's showing empty fields on cmdb_ci_computer table as well as on alm_hardware table but when i checking transform records which loaded in that i can find the records are there.
 
Can you please help me going on multiple issues.
 
Thanks,
JRY

What I'm seeing from where this thread has gone (sorry I had production issues yesterday), you are looking at two tables cmdb_ci and alm_hardware along with a side issue of setting the state correctly.

To start ignore the question of setting the state.  Focus on what is most important and address the issues one at a time.

The first issue is what table does the transform map update? Does the transform map have the Run business rules box checked?  If so do you have any BRs that cross populate the other table or do your transform scripts apply the data to both tables?

Have you confirmed that there are not security constraints that prevent you from deleting certain records?

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster