How to hide attachments on incident form for end user if the attachment is attached by ITIL users

Rajesh Mushke
Mega Sage
Mega Sage

Hi All,

I want to hide attachments on incident form for end users if it is added by ITIL users/ any role users,


But still end users can attach the attachments and they can manage the attachments which are attached by end users.

Thanks in advance.!!!

Thanks,

Rajashekhar Mushke

Community Leader



Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
1 ACCEPTED SOLUTION

Sample Script:

 

before query business rule on sys_attachment table.

 

(function executeRule(current, previous /*null when async*/) {
	
	// Add your code here
	
	if (!gs.hasRole('itil') && gs.getSession().isInteractive()) {
		var u = gs.getUserName();
		var q = current.addQuery('sys_created_by', u);
		q.addOrCondition('sys_updated_by', u);
		gs.log('query restricted for user: ' + u);
	}
	
	
})(current, previous);

 

you try something like this .

 

https://docs.servicenow.com/bundle/london-application-development/page/script/business-rules/concept...

 

https://www.servicenowguru.com/scripting/business-rules-scripting/controlling-record-access-before-q...

View solution in original post

7 REPLIES 7

Thanks for the quick response bro, perfectly working. Thanks, Rajashekhar Mushke Community Leader


Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Hello Harsh

i have a similar requirement for Security incidents where we are enabling end users to create there attachments from Service portal, however we need to restrict the attachments added by security analysts on the Security incidents, there is an attachment generated for post incident report which we do not wish to show to end users. How can i restrict this,

I tried using Before query BR as below and seems not to be working:

(function executeRule(current, previous /*null when async*/) {

// Add your code here

if (!gs.hasRole('sn_si_analyst') &&(current.table_name == 'sn_si_incident') && gs.getSession().isInteractive()) {
var usr = gs.getUserName();
var cur = current.addQuery('sys_created_by', usr);
cur.addOrCondition('sys_updated_by', usr);
gs.log('query restricted for user: ' + usr);
}


})(current, previous);

 

Can you please help me how can i do it and what i am doing wrong? if i dont use table name in the if statement as marked in red above it works, but then it works for all tables which is not desired?

Hello Harshvardhan,

Can you please help on the below query.