Display a different HW Asset Form in the Portal depending on AD Group Membership
Does anyone know if it's possible to have a different HW Asset form display in the Portal based on AD membership? We want to share our SCSM environment between our Server and Desktop folks but they have slightly different requirements for the fields they need on the HW Asset record. I know how to move fields around on the portal forms and how to create new tabs, but essentially what I would like to do is create a Server Tab and a Desktop Tab and have the appropriate tab display based on the AD group membership of the logged in user.
Thanks,
Ian
Best Answer
-
Geoff_Ross Cireson Consultant O.G.Hi Ian,
This is not possible in the standard way as you can do with Work Item forms but you do some cleverness with java script to hide certain elements based on AD group membership. Create your forms with all the tabs and then hide the custom tabs for users who aren't member of a group. This combines code from @Morten_Meisler 'Target AD Groups for Custom Tasks' and @seth_coussens 'Dynamic Forms'var url = window.location.href; if(url.indexOf("/AssetManagement/HardwareAsset/Edit/") > -1 ) { var GroupName = "DOMAIN\\MyADGroup" $.ajax({ url: 'http://' + window.location.host + '/api/V3/User/GetUsersGroups', async: true, //this is the default but showing that it can be turned off data: { id: session.user.Id }, type: "GET", //this particular portal API call is a GET type statusCode: { 200: function (data) { //Call function to hide or show task hideShowTab(data); } }, error: function (jqXHR, textStatus, errorThrown) { //debug console.log(errorThrown); //debug console.log(textStatus); } }); function hideShowTab (data) { var IsMemberOfGroup = false; //for each returned group that user is member of.. $(data).each(function () { console.log(this.Name) //Check if the returned group matches our groupname if (this.Name === GroupName) { IsMemberOfGroup = true; } }); if (IsMemberOfGroup) { //User is member - tab will be shown console.log("User: " + session.user.Name + " is member of group: " + GroupName) } else { //User is not member of group - Hide tab console.log("User: " + session.user.Name + " is NOT member of group: " + GroupName) $('a[data-toggle=tab]').each(function() { if(this.innerText === 'CUSTOM TAB') { $(this).hide(); } }); } } }
5
Answers
This is not possible in the standard way as you can do with Work Item forms but you do some cleverness with java script to hide certain elements based on AD group membership. Create your forms with all the tabs and then hide the custom tabs for users who aren't member of a group. This combines code from @Morten_Meisler 'Target AD Groups for Custom Tasks' and @seth_coussens 'Dynamic Forms'