How to make Attachements Private or Public.

Rohant Joshi2
Kilo Expert

Hello,

 

I have a requirement to make attachments to a form as public or private. I have added a checkbox on attachement form named "Is Private file".At the time of attachement if I check the check box, this attachement is private and should be visible to only ITIL and admins. If I dont check this check box by default this attachement will be public and visible to all.

 

I have tried this on demo019. But I dont find way to proceed to make this functionality work.

 

Can anyone guide me on that.

Thanks in advance.

19 REPLIES 19

Raj80
Tera Contributor

Hello Rohant,



Try with using encryption Encryption Support - ServiceNow Wiki



Thanks & Regards,


Raju.


jean-lucchatton
Kilo Guru

Hi Rohant,



Do you succeeded with your implementation ? We have the same need. Could you give us your solution and the ui page modification that you have done   ?



Thanks


Jean-Luc


Preeti4
Giga Guru

Hi Rohant,

 

Please suggest how to add a check box to attachment form

I also have same requirement where I need to add one check box on Attachment form which changes value in a field on Attachment table (created a new check box field to identify which attachment to be restricted ). Please let me know how can I add a check box on Attachment form and how can I pass value from the check box when selected as 'true' to attachment table.

 I have written ALC on attachment table based on the true/false value on the new field on attachment table that is working perfectly fine. I only need a way to send true/false value for Private attachments from Incident form.

 

Please suggest.

Christian Engs2
Giga Contributor

Hi Prrti

I also had the same need and I ended up writing a onLoad client script adding checkboxes to dialog and to files on top of the form, see image and script below (developed in London-version, indentation lost on pasting the script).

I hope this can be of any help, regards

Christian

find_real_file.png

find_real_file.png

function onLoad() {
try {
jQuery("#header_add_attachment,#header_attachment_list_label").click(function() {
setTimeout(function() {
addCheckboxes("#attachment_table_body ");
var modalOpen = setInterval(function(){
addCheckboxes("#attachment_table_body ");
}, 1500);

jQuery("#attachment_closemodal").click(function() {
clearInterval(modalOpen);
setTimeout(function() { addCheckboxes(""); }, 0);
});
}, 1000);
});

// On load
addCheckboxes("");
}
catch (e) {
console.log("Error:: Set attachments private");
console.log(e);
}

function addCheckboxes(selectPrefix) {
var attachments = jQuery(selectPrefix + 'a[class*="rename"]');
for (var i = 0; i < attachments.length; i++) {
var attachmentSysId = attachments[i].className.split("_")[1];
var gr = new GlideRecord("sys_attachment");
gr.addQuery("sys_id", attachmentSysId);
gr.query(function(grAttachment) {
if (grAttachment.next()) {
try {
var allreadyAdded = jQuery('#private-checkbox-' + (selectPrefix != "" ? "modal-" : "") + grAttachment.sys_id);
//console.log(allreadyAdded);
var checked = "";
if (grAttachment.u_private == "true") {
checked = "checked";
}
if (!allreadyAdded[0]) {
var renameLink = jQuery(selectPrefix + 'a.attachment.rename_' + grAttachment.sys_id)[0];
renameLink.insert({before:'[<input type="checkbox" id="private-checkbox-' + (selectPrefix != "" ? "modal-" : "") + grAttachment.sys_id + '" ' + checked + ' value="' + grAttachment.sys_id + '">private]'});
jQuery('#private-checkbox-' + (selectPrefix != "" ? "modal-" : "") + grAttachment.sys_id).change(function() {
try {
if (jQuery(this).prop("value").length == 32) {
var grSavePrivateCheckbox = new GlideRecord("sys_attachment");
grSavePrivateCheckbox.addQuery("sys_id", jQuery(this).prop("value"));
grSavePrivateCheckbox.query(); // using synchronous on the save, will not affect page load
if (grSavePrivateCheckbox.next()) {
grSavePrivateCheckbox.u_private = this.checked;
grSavePrivateCheckbox.update();
}
}
}
catch (e) {}
});
}
else {
jQuery('#private-checkbox-' + (selectPrefix != "" ? "modal-" : "") + grAttachment.sys_id).prop("checked", checked == "checked");
}
}
catch (e) {}
}
});
}
}
}