We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Roles required to Create attachment

abhiyadav2001
Giga Expert

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

1 ACCEPTED SOLUTION

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);


}


View solution in original post

9 REPLIES 9

Hi Abhijeet,



Thanks for the update.


I have checked with your script and it was working fine for "ITIL" users.


I am sure there should be an issue with ACL on your instance.





Thanks


Pradeep Sharma


It was instance issue. It was not working that day.. surprisingly, it started working now ! ( its a good surprise though )



Thanks,


Abhijeet


Slava Savitsky
Giga Sage

How do you call that script include while being logged in as a non-admin user? Can that user add an attachment manually via the UI?


I made a script 'Client callable'. I have created a 'UI page' and a button on that. On that button click, I am creating attachment by using script.



When I run that UI page by using 'Try It ' , its creating a new incident and attachment with that. However, when intended user views that page, that button click is not doing anything !


abhiyadav2001
Giga Expert

I was trying for a whole day and it was not working.. after couple of days.. its working absolutely fine without any change ! its a good surprise though..