How can we use icon link widget to redirect to different pages when user clicks on the widget based on his role in service portal?

rkreddy
Giga Expert

Hi Everyone,

Hope everything is going good.

I have two icon link widgets, "create new incident" and "Create new Custom table record" and each redirects to different pages in service now instance. For example, Widget A directs to Create new Incident record page and Widget redirects to Create new Custom table record page. Now, I want to make these widgets visible to all the users irrespective of their role, but if user doesn't have role on custom table, then when he clicks on "create new custom table record" widget, then he needs to redirect to the catalog item in service portal.

Thank you.

1 ACCEPTED SOLUTION

Shivani Singh1
Tera Guru

Hello,

You have to clone and customize Icon Link to have this functionality,

In server script, add these lines

if(gs.hasRole("<role name>"))

{

var gr = $sp.getInstanceRecord();
data.href = $sp.getMenuHREF(gr);

}

else

{

data.href = "?id=sc_cat_item&sys_id=<sys-id of catalog item>";

}

Fill <role name> & <sys-id> as per your requirement.

Please mark helpful if it solves the purpose.

View solution in original post

19 REPLIES 19

You can keep the other ones as-is, because they are working fine, right?

So let them be , it's only with HR case. Apply this customized widget for it only.

I have used the same Custom icon link widget for both "create new student record" and create new Application form record which redirects to specific pages. So, inorder to write this scripts based on role, Can i give different icon link widgets to two tables by placing respective role in the script.

As per my understanding, you have another form which also requires this role based scenario ?

You want to apply same script to that also but with different role, right?

In this case, if role is different from u_student_user then you need to add this script in another Icon link widget otherwise it will conflict with previous one.

Yes exactly, so for other other I create another cloned icon link widget and will write the script in that.

Great!

Please mark helpful and accept the solution if everything works fine.