Is it Safe to Remove Orphaned Records for a Scoped App from sys_metadata?

Rogers Cadenhe1
Giga Guru

I am trying to commit changes in a scoped application to my company's private git repo.

When I open Studio and click Source Control, Commit Changes, it fails with the message "an error occurred while writing metadata files for application."

ServiceNow has a KB article describing the solution. In a nutshell, the problem is that some records in the sys_metadata table refer to a record in the application that does not exist. The solution is to delete those orphaned records.

Before I do this, I wanted to find out whether there are any potential drawbacks to removing a record from sys_metadata. Does it have any impact on the functioning of the scoped app? Are there any other reasons to be leery of doing this?

Also, if you read the solution, why does it require exporting records as XML, changing their sys_script action attribute from "INSERT_OR_UPDATE" to "DELETE", and importing the XML back into the instance? It seems like deleting each record manually would have the same result.

2 REPLIES 2

Cody Smith _ Cl
Tera Guru

Hello Roger,

 

It would be fine to Delete those records if they are orphaned. If they are not tied to anything then there would be no impact of removing them. 

The INSERT to DELETE is specified as:

3. Open the XML file and use find and replace to adjust: 

Before: <sys_script action="INSERT_OR_UPDATE"> After: <sys_metadata action="DELETE">  After: <sys_metadata action="DELETE">

That is different from just manually deleting them because its calling 'sys_metadata action' for the delete instead of 'sys_script action' which is telling it 'sys_metadata' which makes it known that its a scoped app. 

 

If my answer was helpful, or solved your issue, please mark it as Helpful / Correct.
Thank you,
Cody Smith
 

Daryl5
Kilo Contributor

One thing that was confusing from the linked post, the double 'After' section.  What it did NOT explain was that the value you were editing was the start-tag of an XML element - you also need to modify the end-tag of the same element. When I followed the instructions as given, I got the message 'File _fix.xml is not valid XML and has been deleted'

In the above example, you would have needed to replace both

<sys_script action="INSERT_OR_UPDATE">

AND the following end-tag of

</sys_script>

with 

<sys_metadata action="DELETE">

and

</sys_metadata>

respectively per entry in your exported XML file.

 

I hope this save someone the headache that I had while running into this same problem!