- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 05:57 AM
Hello:
We would like to copy many records from one table to another, including managed documents on each record's Documents related list. The procedures below work for individual records, and we would like to duplicate this using a script, eventually as part of a transform map. (GlidesysAttachment works for attachments, but doesn't seem to work for managed documents). We'd appreciate any pointers or advice on how to create a script to copy managed documents from one record to another. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 05:48 AM
We did manage to do this, here is the onComplete transform map script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grSource = new GlideRecord(<’source table>');
grSource.addQuery('sys_id', source.u_sys_id);
grSource.query();
grSource.next());
grTarget = new GlideRecord(‘<target table>');
grTarget.addQuery('sys_id', target.sys_id);
grTarget.query();
grTarget.next();
grRefSource = new GlideRecord('ds_document_references');
grRefSource.addQuery('table_name', ‘<source table>’);
grRefSource.addQuery('target_record', grSource.sys_id);
grRefSource.query();
while (grRefSource.next()) {
create();
}
function create() {
var gr = new GlideRecord('ds_document_references');
gr.initialize();
var gr2 = new GlideRecord('ds_document');
gr2.addQuery('sys_id', grRefSource.document);
gr2.query();
if (gr2.next()) {
gr.document = gr2.sys_id;
gr.table_name = ‘<target table>’;
gr.target_record = grTarget.sys_id;
gr.insert();
}
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 05:48 AM
We did manage to do this, here is the onComplete transform map script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var grSource = new GlideRecord(<’source table>');
grSource.addQuery('sys_id', source.u_sys_id);
grSource.query();
grSource.next());
grTarget = new GlideRecord(‘<target table>');
grTarget.addQuery('sys_id', target.sys_id);
grTarget.query();
grTarget.next();
grRefSource = new GlideRecord('ds_document_references');
grRefSource.addQuery('table_name', ‘<source table>’);
grRefSource.addQuery('target_record', grSource.sys_id);
grRefSource.query();
while (grRefSource.next()) {
create();
}
function create() {
var gr = new GlideRecord('ds_document_references');
gr.initialize();
var gr2 = new GlideRecord('ds_document');
gr2.addQuery('sys_id', grRefSource.document);
gr2.query();
if (gr2.next()) {
gr.document = gr2.sys_id;
gr.table_name = ‘<target table>’;
gr.target_record = grTarget.sys_id;
gr.insert();
}
}
})(source, map, log, target);