- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-17-2018 01:12 PM
Hi,
I have seen multiple requests for copying table structure from one instance to another instance and sometimes save it to update set as if it is one time you can even export and import the record. So i came up with a fix script that can copy the table and its related structure to your current update set. Ensure the update set you want to store all the records is the current update set. Also ensure the fix script that you are going to create is Unloadable - Checked.
Create a fix script and make it unloadable true and copy the code below and run the script. I have covered the following relations and scenarios and if you feel something else can be added to this script feel free to comment below and i will update it.
1. Table
2. Dictionary
3. Documentation
4. Client Script
5. Business Rules
6. UI policy
7. Data policy
8. Style
9. ACL
10. Choice list
11. Relation
12. UI action
13. Workflow
14. Section, Form and Elements
15. Modules
copyTableStructureToUpdateSet('incident'); // replace incident with the table name you want to export
function copyTableStructureToUpdateSet(tableName) {
var um = new GlideUpdateManager2();
// um.saveRecord(current);
// Copy table
var tableGR = new GlideRecord("sys_db_object");
if(tableGR.get("name", tableName)) {
um.saveRecord(tableGR);
// Copy dictionary
var dictGR = new GlideRecord("sys_dictionary");
dictGR.addQuery("name", tableName);
dictGR.query();
while(dictGR.next()) {
um.saveRecord(dictGR);
}
// Copy documentation
var docGR = new GlideRecord("sys_documentation");
docGR.addQuery("name", tableName);
docGR.query();
while(docGR.next()) {
um.saveRecord(docGR);
}
// Choice
var choiceGR = new GlideRecord("sys_choice");
choiceGR.addQuery("name", tableName);
choiceGR.query();
while(choiceGR.next()) {
um.saveRecord(choiceGR);
}
// Client Script
var clientGR = new GlideRecord("sys_script_client");
clientGR.addQuery("table", tableName);
clientGR.query();
while(clientGR.next()) {
um.saveRecord(clientGR);
}
// UI policy
var policyGR = new GlideRecord("sys_ui_policy");
policyGR.addQuery("table", tableName);
policyGR.query();
while(policyGR.next()) {
um.saveRecord(policyGR);
}
// Business Rule
var busGR = new GlideRecord("sys_script");
busGR.addQuery("collection", tableName);
busGR.query();
while(busGR.next()) {
um.saveRecord(busGR);
}
// ACL script
var aclGR = new GlideRecord("sys_security_acl");
aclGR.addQuery("type", "record");
aclGR.addEncodedQuery("name=" + tableName + "^ORnameSTARTSWITH" + tableName + ".");
aclGR.query();
while(aclGR.next()) {
um.saveRecord(aclGR);
}
// Relation
var relGR = new GlideRecord("sys_relationship");
relGR.addQuery("basic_apply_to", tableName);
relGR.query();
while(relGR.next()) {
um.saveRecord(relGR);
}
// UI actions
var actionGR = new GlideRecord("sys_ui_action");
actionGR.addQuery("table", tableName);
actionGR.query();
while(actionGR.next()) {
um.saveRecord(actionGR);
}
// Style
var styleGR = new GlideRecord("sys_ui_style");
styleGR.addQuery("name", tableName);
styleGR.query();
while(styleGR.next()) {
um.saveRecord(styleGR);
}
// Data policy
var dpGR = new GlideRecord("sys_data_policy2");
dpGR.addQuery("model_table", tableName);
dpGR.query();
while(dpGR.next()) {
um.saveRecord(dpGR);
}
// Workflow
var wfGR = new GlideRecord("wf_workflow_version");
wfGR.addQuery("table", tableName);
wfGR.addQuery("published", true);
wfGR.query();
while(wfGR.next()) {
um.saveRecord(wfGR);
}
// Section
var uiSecGR = new GlideRecord("sys_ui_section");
uiSecGR.addQuery("name", tableName);
uiSecGR.query();
while(uiSecGR.next()) {
um.saveRecord(uiSecGR);
}
// Form Section
var uiFormSecGR = new GlideRecord("sys_ui_form_section");
uiFormSecGR.addEncodedQuery("sys_ui_form.name=" + tableName);
uiFormSecGR.query();
while(uiFormSecGR.next()) {
um.saveRecord(uiFormSecGR);
}
// Section elem
var uiSecElemGR = new GlideRecord("sys_ui_element");
uiSecElemGR.addEncodedQuery("sys_ui_section.sys_name=" + tableName);
uiSecElemGR.query();
while(uiSecElemGR.next()) {
um.saveRecord(uiSecElemGR);
}
// Module
var moduleGR = new GlideRecord("sys_app_module");
moduleGR.addQuery("name", tableName);
moduleGR.query();
while(moduleGR.next()) {
um.saveRecord(moduleGR);
}
}
}
- 2,316 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@venkatiyer1 Thank you for a great article.
I think we can leverage the OOB 'addToUpdateSetUtils' API to add all the updates to an update set. Here is a sample script:
//Create an update set in your application scope and make it your current update set before executing this script
var dbGr = new GlideRecord("sys_db_object");
if (dbGr.get(<sys_id_of_table>)){
new global.addToUpdateSetUtils().addToUpdateSet(dbGr);
}
This will add the following updates to the current update set:
- Access Control
- Access Roles
- Application Menu
- Business Rule
- Choice list
- Client Script
- Dictionary
- Field Label
- Form Layout
- Form Sections
- List Layout
- Module
- Related Lists
- Role
- Table
- UI Action
- UI Action Role
- UI Policy
- UI Policy Action
We have to keep in mind about the other elements that might be needed for the full workflow of the table like:
- Notifications
- Email scripts
- Dashboards
- Reports
- Script Includes
- Flow formatter
- Event registries
Note: This will create a bunch of update sets depending upon the cross scope artifacts in your table. Careful review of the update will reduce the number of preview problems when moved to a different instance.