- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 03:47 AM
Hi team,
i am trying to assign attachment sys_id in to a string field, in "insert business rule on signature_image" table.
I am getting @@@@@1 , @@@@@2 , logs only, i am getting sys_id of the attachment in @@@@@2 log, but not updating in to that field
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.log('@@@@@ABC ');
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',current.document);
request.query();
if(request.next()){
gs.log('@@@@@1 ABC number '+ request.number);
gs.log('@@@@@2 ABC sys id '+current.getUniqueValue());
var id = attachementid();
if(id == 'NOValue'){
gs.log('@@@@@3'+u_current_attachment_sysid);
request.u_current_attachment_sysid = u_current_attachment_sysid;
request.update();
id = attachementid();
}
if(id != 'NOValue') {
gs.log('@@@@@4'+u_current_attachment_sysid);
request.u_current_attachment_sysid = id;
request.update();
}
}
function attachementid(){
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.getUniqueValue());
gs.log('ABC jaifdiadsf');
attachment.query();
gs.log('@@@@@5'+u_current_attachment_sysid);
if(attachment.next()){
gs.log('@@@@@6'+u_current_attachment_sysid);
return attachment.sys_id;
}
else
gs.log('@@@@@7'+u_current_attachment_sysid);
return 'NOValue';
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2019 12:05 AM
Hello Deepthi,
Could you please mark the answer as correct as we will not leave this thread unanswered
Regards,
Chalan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 10:39 PM
ya tried, pls see below,
(function executeRule(current, previous /*null when async*/) {
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',current.document);
request.query();
if(request.next()){
var id = attachmentSys_id(current.getUniqueValue());
gs.log('@@@@@3'+id);
request.u_current_attachment_sysid = id;
request.update();
}
})(current, previous);
function attachmentSys_id(signatureimagesysid){
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',signatureimagesysid);
attachment.query(); //you are missing this line of code
if(attachment.next()){
gs.log('@@@@@3'+attachment.sys_id.toString());
return attachment.sys_id.toString();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 10:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 11:02 PM
ya even it is working in my personal dev with this code, but in company dev it is not going in to if condition
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.log('ABC ');
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',current.document);
request.query();
if(request.next()){
gs.log('ABC number '+ request.number);
gs.log('ABC sys id '+current.getUniqueValue());
var id = attachementid();
if(id == 'NOValue'){
id = attachementid();
}
if(id != 'NOValue') {
request.u_current_attachment_sysid = id;
request.update();
}
}
function attachementid(){
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.getUniqueValue());
gs.log('ABC jaifdiadsf');
attachment.query();
if(attachment.next()){
return attachment.sys_id;
}
else
return 'NOValue';
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 11:10 PM
Hi Deepti,
In the below script you have created, what is current.document and current.getUniqueValue()??
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.log('@@@@@ABC ');
var signatureimagesysid = current.getUniqueValue();
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',current.document);
request.query();
if(request.next()){
gs.log('@@@@@1 ABC number '+ request.number);
gs.log('@@@@@2 ABC sys id '+current.getUniqueValue());
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',signatureimagesysid);
if(attachment.next()){
gs.log('@@@@@3'+u_current_attachment_sysid);
request.u_current_attachment_sysid = signatureimagesysid.tostring();
request.update();
}
}
})(current, previous);
I'm assuming that current.document and current.getUniqueValue() is having the same sys_id because the query you have written is like that.
Please run the below script in the background script it will not update your record but should print the attachment sys_id.
var Req_sys_id = '<Give your request sys_id>';
var request = new GlideRecord('sc_request');
request.addQuery('sys_id',Req_sys_id);
request.query();
if(request.next()){
var id = attachmentSys_id(Req_sys_id);
gs.print('@@@@@3'+id);
//request.u_current_attachment_sysid = id;
//request.update();
}
function attachmentSys_id(signatureimagesysid){
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',signatureimagesysid);
attachment.query(); //you are missing this line of code
if(attachment.next()){
gs.print('@@@@@3'+attachment.sys_id.toString());
return attachment.sys_id.toString();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 11:25 PM
hi,
i dont have back ground script role in my dev 😞