- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2019 02:52 AM
Hi All,
I have one requirement , whenever I submit a request from catalog item, new record should be created in data source table and attachment from RITM should be copied to the created data source.
Written the below code to copy the attachment from RITM to data source.Here I have hard coded one data source sys_id to copy the attachment,How can I create a new data source for each request in data-source table?
(function executeRule(current, previous /*null when async*/) {
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sc_req_item', current.sys_id, 'sys_data_source', '0ec1ab04db8bbf4019d81ffa68961900');
gs.log("test","zero");
})(current, previous);
Need some suggestion Guys!
Thanks in Advance!
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2019 03:10 AM
Thanks Siva !There are some small corrections in your code,below code works perfect!
(function executeRule(current, previous /*null when async*/) {
function createDS(){
var dat = new GlideRecord('sys_data_source');
dat.initialize();
dat.name= 'newDSource';
return dat.insert();
var dataSource = createDS();
//Copy Attachment
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSource);
gs.log("test","zero");
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2019 03:01 AM
You can have a br work for only your catalog item and after insert of that req item you need to glide sys_data_source table and initialize and set up some field values what all are required
The sample code would be
function createDS(){
var dat = new GlideRecord('sys_data_source');
dat.initialize();
dat.fieldName1= value;
dat.fieldName2 = value;
return dat.insert; // you willl get the glide record object of the data source with sys_id value as areference here
}
var dataSource = createDS();
and then using dataSource.sys_id in your code you specified in the question , you can copy the attachment from the RITM to the created data source
Mark this response as correct if that really helps
Thanks,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2019 03:10 AM
Thanks Siva !There are some small corrections in your code,below code works perfect!
(function executeRule(current, previous /*null when async*/) {
function createDS(){
var dat = new GlideRecord('sys_data_source');
dat.initialize();
dat.name= 'newDSource';
return dat.insert();
var dataSource = createDS();
//Copy Attachment
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sc_req_item', current.sys_id, 'sys_data_source', dataSource);
gs.log("test","zero");
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2019 07:37 PM
You mean to say insert() i didnot use and kept insert?
That was not the original code snippet intented to use. Without knowing your field names ,its not possible for me to give you the exact script . I just gave you the pseudo code.
Anyways if my response drived you to achieve your requirement, thats fine for me even though you donot mark it as correct. 🙂
Thanks,
Siva