Steps for using update sets to export/import Document Intelligence use cases between SN instancesSummaryExport a use case to an update set Export a use case for use in another ServiceNow instance. Before you begin Role required: sn_docintel.manager About this task These steps describe how to export a DocIntel use case, which is also called a task definition in segments of the script. Use case is the updated term for a task definition. For more information, see Terminology. Procedure Copy the script provided in Use Case Export Script below.Navigate to System Definition > Scripts – Background.Paste the script in the Run script box.In a new tab, navigate to Document Intelligence > Use Cases.Open the use case you want to export.Copy the sys_id from the URL. For example, copy 9f426b878749e110ba3540809bbb35a6 from the following URL: https://instancename.service-now.com/now/docintel-admin/usecase/9f426b878749e110ba3540809bbb35a6 On the Scripts - Background tab, paste the sys_id in the first line for the TASK_DEFINITION_TO_EXPORT_SYS_ID variable. For example, the line of the script should look like the following line: var TASK_DEFINITION_TO_EXPORT_SYS_ID = "9f426b878749e110ba3540809bbb35a6"; Click Run script to run the background script in the global scope. This script takes several minutes to execute. Navigate to System Update Sets > Local Update Sets. You may see several update sets with names starting with the name of the use case. Click into each update set where the name contains "global update set" and "global update set task x-y" and click Export Update Set Batch to XML in the Related Links to download the XML files. Note: In the name “global update set task x-y”, x-y refers to a range of tasks that are part of update set. If you have 100 document tasks, you will find two batch update sets with the following in the name “global update set task 1-50” and “global update set task 51-100”. Result The use case is exported to your computer as XML files. Import a use case Import a use case for use in your ServiceNow instance. Before you begin Update sets for a use case are downloaded according to the steps provided in Export a use case. Role required: sn_docintel.manager Procedure Navigate to System Update Sets > Retrieved Update Sets.Under Related Links, select Import Update Set from XML.Select the "global update set" XML file and upload it.Open the “global update set” record.Click Preview Update Set Batch. There may be a few errors for di_extracted_values, "Could not find a record in di_image for column image referenced in this update"). This is because those extracted values are empty and don't have a di_image. You can safely select Accept remote update.If there are no other errors, you can Commit Update Set Batch.Repeat steps 3 - 7 for each update set. Result The use case is imported into the instance and appears in the use cases list. Use Case Export Script var TASK_DEFINITION_TO_EXPORT_SYS_ID = ""; var TASK_BATCH_SIZE = 50; var scopeToUpdateSet = {}; var taskDefinitionName = ""; function getTaskSuffix(taskBatchNum) { if (taskBatchNum != null) { return ( " task " + ((taskBatchNum - 1) * TASK_BATCH_SIZE + 1) + "-" + taskBatchNum * TASK_BATCH_SIZE ); } else { return ""; } } function createUpdateSet(taskBatchNum) { var taskSuffix = getTaskSuffix(taskBatchNum); var globalNameSuffix = " global update set" + taskSuffix; var docintelNameSuffix = " docintel update set" + taskSuffix; var globalKey = "global" + taskSuffix; var docintelKey = "19b40605edae411005e8007f82757635" + taskSuffix; // Create a new global update set var globalUpdateSetGR = new GlideRecord("sys_update_set"); globalUpdateSetGR.initialize(); globalUpdateSetGR.name = taskDefinitionName + globalNameSuffix; globalUpdateSetGR.application = "global"; var globalUpdateSetID = globalUpdateSetGR.insert(); scopeToUpdateSet[globalKey] = globalUpdateSetID; // Create a new DocIntel scope update set var updateSetGR = new GlideRecord("sys_update_set"); updateSetGR.initialize(); updateSetGR.name = taskDefinitionName + docintelNameSuffix; updateSetGR.application = "19b40605edae411005e8007f82757635"; updateSetGR.parent = globalUpdateSetGR.sys_id; var updateSetID = updateSetGR.insert(); scopeToUpdateSet[docintelKey] = updateSetID; } function saveToUpdateSet(glideRecord, taskCount) { var gum; var scope = String(glideRecord.sys_scope || "global"); if (scope !== "global" && scope !== "19b40605edae411005e8007f82757635") { gs.info("unknown scope: " + scope + "|" + glideRecord.getDisplayValue()); return; } var taskBatchNum = taskCount ? Math.ceil(taskCount / TASK_BATCH_SIZE) : null; var updateSetSysId = scopeToUpdateSet[scope + getTaskSuffix(taskBatchNum)]; if (!updateSetSysId) { createUpdateSet(taskBatchNum); updateSetSysId = scopeToUpdateSet[scope + getTaskSuffix(taskBatchNum)]; } try { gum = new GlideUpdateManager2(updateSetSysId); } catch (e) { var gus = new GlideUpdateSet(); gus.set(updateSetSysId); gum = new GlideUpdateManager2(); } gum.saveRecord(glideRecord); } function exportTaskDefinition(taskDefinitionId) { var currentUpdateSetSysId = gs.getPreference("sys_update_set"); // Get task definition var taskDefinitionGR = new GlideRecord("di_task_definition"); if (!taskDefinitionGR.get(taskDefinitionId)) { gs.info("task definition not found."); return; } taskDefinitionName = taskDefinitionGR.getValue("display_name"); createUpdateSet(null); //Push records into the current update set // Task Definition saveToUpdateSet(taskDefinitionGR); saveToUpdateSet(taskDefinitionGR.ml_definition_ocr.getRefRecord()); saveToUpdateSet(taskDefinitionGR.ml_definition_training.getRefRecord()); saveToUpdateSet(taskDefinitionGR.ml_definition_prediction.getRefRecord()); saveToUpdateSet( taskDefinitionGR.ml_definition_pdf_preprocessing.getRefRecord() ); // KeyGroups var keyGroupGR = new GlideRecord("di_key_group"); keyGroupGR.addQuery("task_definition", taskDefinitionId); keyGroupGR.query(); while (keyGroupGR.next()) { saveToUpdateSet(keyGroupGR); } // Keys var keyGR = new GlideRecord("di_key"); keyGR.addQuery("task_definition", taskDefinitionId); keyGR.query(); while (keyGR.next()) { saveToUpdateSet(keyGR); } // ML Solutions var mlSolutionGR = new GlideRecord("ml_solution"); mlSolutionGR.addQuery("solution_name", "CONTAINS", taskDefinitionId); mlSolutionGR.addQuery("active", true); mlSolutionGR.query(); while (mlSolutionGR.next()) { saveToUpdateSet(mlSolutionGR); // ML Model Artifacts var mlModelArtifactGR = new GlideRecord("ml_model_artifact"); mlModelArtifactGR.addQuery("solution", mlSolutionGR.sys_id); mlModelArtifactGR.query(); while (mlModelArtifactGR.next()) { saveToUpdateSet(mlModelArtifactGR); } // ML progress tracker saveToUpdateSet(mlSolutionGR.progress_tracker.getRefRecord()); } // Tasks var taskCount = 0; var taskGR = new GlideRecord("di_task"); taskGR.addQuery("task_definition", taskDefinitionId); taskGR.query(); while (taskGR.next()) { taskCount += 1; saveToUpdateSet(taskGR, taskCount); // PDFs var pdfGR = new GlideRecord("di_pdf"); pdfGR.addQuery("task", taskGR.sys_id); pdfGR.query(); while (pdfGR.next()) { saveToUpdateSet(pdfGR, taskCount); } // Images var imageGR = new GlideRecord("di_image"); imageGR.addQuery("task", taskGR.sys_id); imageGR.query(); while (imageGR.next()) { saveToUpdateSet(imageGR, taskCount); // Candidate Scores var candidateScoreGR = new GlideRecord("di_candidate_score"); candidateScoreGR.addQuery("image", imageGR.sys_id); candidateScoreGR.query(); while (candidateScoreGR.next()) { saveToUpdateSet(candidateScoreGR, taskCount); } } // Extracted Values var extractedValueGR = new GlideRecord("di_extracted_value"); extractedValueGR.addQuery("task", taskGR.sys_id); extractedValueGR.query(); while (extractedValueGR.next()) { saveToUpdateSet(extractedValueGR, taskCount); } // Prediction Inputs var predictionInputGR = new GlideRecord("di_prediction_input"); predictionInputGR.addQuery("task", taskGR.sys_id); predictionInputGR.query(); while (predictionInputGR.next()) { saveToUpdateSet(predictionInputGR, taskCount); } // Training Inputs var trainingInputGR = new GlideRecord("di_training_input"); trainingInputGR.addQuery("task", taskGR.sys_id); trainingInputGR.query(); while (trainingInputGR.next()) { saveToUpdateSet(trainingInputGR, taskCount); } } // Reset current update set new GlideUpdateSet().set(currentUpdateSetSysId); // Mark as completed for (var updateSetKey in scopeToUpdateSet) { var globalUpdateSetGR = new GlideRecord("sys_update_set"); globalUpdateSetGR.get(scopeToUpdateSet[updateSetKey]); globalUpdateSetGR.setValue("state", "complete"); globalUpdateSetGR.update(); } } exportTaskDefinition(TASK_DEFINITION_TO_EXPORT_SYS_ID); Related Links Document Intelligence product documentation