Notifications

520 views

Symptoms


User attempts to link a developed application to source control and receives the following error "an error occurred while writing metadata files for application" 

Cause


The most likely cause for this error is related to orphan data within the application which is being linked to source control. If orphan data exists the user will not be able to link the scoped application to source control until the orphan data has been identified and removed.

Resolution


The following script can be executed to return records which are orphaned at the child level table (i.e. the sys_metadata record exists for a business rule however the business rule does not exist on sys_script).In a list of application files for a specific scoped application there can be a large number for files spread across a large list of classes and manually identifying orphans can be tedious. To identify orphans users can run the following script (user will need to populate their own encoded query string for the variable myString).

var myString='your encoded query string here' 
var a1 = new GlideRecord('sys_metadata'); 
a1.addEncodedQuery(myString); 
a1.query(); 
while (a1.next()) 
{ 
var a2 = new GlideRecord(a1.sys_class_name); 
a2.addQuery('sys_id',a1.sys_id); 
a2.query(); 
if (!a2.next()) 
gs.print('orphaned data exists for ' + a1.sys_id + ' ' + 'sys_class_name is ' + a1.sys_class_name); 
} 

In the following example we have a scoped application called NowCore which has produced the following error when linking to source control.

Here are the list of application files in this scoped application grouped by class:

 

Using the script above with modifications to myString variable, we can query against sys_metadata for all applications files within the NowCore scoped application and then return records where the data is orphaned. 

 

Here is the output of this script:

Using this information we can confirm if in fact the record at the sys_script_level is orphaned as viewing it should return a 'record not found message' 

This screen shot shows the parent record is present and it is in the NowCore scoped application.

If we click into the record we see "record not found" which tells us that the record is in fact orphaned at the child level.

Once we have identified the orphan the following steps can be taken to removed the orphan data:

 1. From the list view on the sys_metadata table build a query for the orphaned data identified from the script above.

2. Export the record(s) as XML.

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">

4. Save the file as _fix.xml, and then select Import XML from the instance

Once the orphan data has been removed the user/admin can now link the application to source control.

 

Additional Information


The script provided here can be modified to find orphans at the child level of any table. It is not solely just for sys_metadata. This applies to tables which are in TPC (Table Per Class) hierarchy. The process to remove orphan data can also be recycled as it does not apply to only sys_metadata. If there are any questions regarding the steps outlined please contact support for assistance.

Article Information

Last Updated:2018-06-05 14:21:41
Published:2018-06-05
Screen Shot 2018-05-07 at 2.34.50 PM.pngScreen Shot 2018-05-07 at 2.36.15 PM.pngScreen Shot 2018-05-07 at 2.40.44 PM.pngScreen Shot 2018-05-07 at 2.40.44 PM.pngScreen Shot 2018-05-07 at 2.42.10 PM.pngScreen Shot 2018-05-07 at 2.51.50 PM.pngScreen Shot 2018-05-07 at 2.53.20 PM.png