- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 04:46 AM
Hi,
I have a 'script include' which creates a .docx file as an attachment. I can execute that script as I am an admin ( I can create attachment through script). However, When I try this through 'non-admin' user, its not working at all !
Do I need to make any changes in Roles ? I can not assign admin role to that user.
I tried to create a new role to 'sys_attachment' . I want to make user 'able to create attachment'.
What could be the possible ways to achieve that ?
Thanks
Abhijeet
Solved! Go to Solution.
- Labels:
-
Enterprise Release Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 05:46 AM
using below script include :
var CreateAttachmentDocwithParam = Class.create();
CreateAttachmentDocwithParam.prototype = Object.extendsObject(AbstractAjaxProcessor,{
_initialize: function() {
},
addAttachment: function () {
// var task = new GlideRecord('incident');
// task.setLimit(1);
// task.query();
// task.next(); //Here is a random task record
var result = this.newItem("result");
var rec = new GlideRecord('incident');
rec.initialize();
rec.short_description = 'Test Creation of Onbording candidate attachment cotract';
rec.caller_id.setDisplayValue('Abhijeet Yadav');
var a = GlideSysAttachment();
var Pssn = this.getParameter('sysparm_ssn');
var text = this.getParameter('sysparm_text');
var formType = this.getParameter('sysparm_formType');
var gdt = new GlideDateTime();
// gs.log(gdt.getValue());
var fileName = formType + gdt.getValue() +'.docx' ;
//gs.log(text);
rec.insert();
result.setAttribute("message", rec.number );
gs.log(rec.number);
a.write(rec, fileName, "application/vnd.openxmlformats-officedoc", text );
},
type: 'CreateAttachmentDocwithParam'
});
=============================================
Calling it on button click from UI page. below is the code :
function createDoc()
{
var ga = new GlideAjax('CreateAttachmentDocwithParam');
ga.addParam('sysparm_name', 'addAttachment');
var name = ${jvar_candidateName};
alert (name);
ga.addParam('sysparm_ssn', 'sample SSN 101010');
element = document.getElementById('contract');
var text = element.textContent || element.innerText;
ga.addParam('sysparm_text', text);
ga.addParam('sysparm_formType', '1099_');
ga.getXML(parseAnswer);
//element = document.getElementById('contract');
//var text = element.textContent || element.innerText;
}
function parseAnswer(response) {
// var answer = response.responseXML.documentElement.getAttribute("incNo");
// alert ('Document is attached to incident : ' + answer );
var result = response.responseXML.getElementsByTagName("result");
var message = result[0].getAttribute("message");
alert('Document is attached to incident : ' +message);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 04:57 AM
Hi Abhijeet,
I had the same issue long back but i am not sure what exactly i did and it worked.
Can you please check if the user has the write access to the table on which the file is attached?
Thanks
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 05:35 AM
I am creating an attachment on 'incident' table. Should I check ACL for incident / sys_attachment ? Is there any way to assign write / create role to the intended 'user group' ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 05:42 AM
Can you please paste your code here so that I can try it on any demo instance.
I'm sorry I really dont remember at this point of time what I modified and it worked for me.
`Pradeep Sharma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2014 05:46 AM
using below script include :
var CreateAttachmentDocwithParam = Class.create();
CreateAttachmentDocwithParam.prototype = Object.extendsObject(AbstractAjaxProcessor,{
_initialize: function() {
},
addAttachment: function () {
// var task = new GlideRecord('incident');
// task.setLimit(1);
// task.query();
// task.next(); //Here is a random task record
var result = this.newItem("result");
var rec = new GlideRecord('incident');
rec.initialize();
rec.short_description = 'Test Creation of Onbording candidate attachment cotract';
rec.caller_id.setDisplayValue('Abhijeet Yadav');
var a = GlideSysAttachment();
var Pssn = this.getParameter('sysparm_ssn');
var text = this.getParameter('sysparm_text');
var formType = this.getParameter('sysparm_formType');
var gdt = new GlideDateTime();
// gs.log(gdt.getValue());
var fileName = formType + gdt.getValue() +'.docx' ;
//gs.log(text);
rec.insert();
result.setAttribute("message", rec.number );
gs.log(rec.number);
a.write(rec, fileName, "application/vnd.openxmlformats-officedoc", text );
},
type: 'CreateAttachmentDocwithParam'
});
=============================================
Calling it on button click from UI page. below is the code :
function createDoc()
{
var ga = new GlideAjax('CreateAttachmentDocwithParam');
ga.addParam('sysparm_name', 'addAttachment');
var name = ${jvar_candidateName};
alert (name);
ga.addParam('sysparm_ssn', 'sample SSN 101010');
element = document.getElementById('contract');
var text = element.textContent || element.innerText;
ga.addParam('sysparm_text', text);
ga.addParam('sysparm_formType', '1099_');
ga.getXML(parseAnswer);
//element = document.getElementById('contract');
//var text = element.textContent || element.innerText;
}
function parseAnswer(response) {
// var answer = response.responseXML.documentElement.getAttribute("incNo");
// alert ('Document is attached to incident : ' + answer );
var result = response.responseXML.getElementsByTagName("result");
var message = result[0].getAttribute("message");
alert('Document is attached to incident : ' +message);
}