Home Analyst Portal

Target AD Groups for Specific Custom Tasks

JD_KeithJD_Keith Customer IT Monkey ✭
Hello all!

I'm working on custom forms for assigning to AD groups and was interested in knowing if it's possible to create custom tasks then target them to a specific AD group.  A little background on what I'm trying to accomplish:  Basically we have a group of users who need to resolve/complete incidents and service requests specifically assigned to their respective group, but we do not want to give them Analyst permissions.  I created a custom form so they are able to assign, change support groups, etc, but they are not able to resolve/complete work items.  Being only End Users, they only have "Print" under their tasks section.  I've tried to rework Geoff_Ross' solution to target an AD group with no luck.  I can only seem to differentiate between an Analyst and an End User.

Has anybody else came across this situation?  I may even be trying to do things the hard way, so I'll take any input at all :)

Comments

  • Morten_MeislerMorten_Meisler Premier Partner Advanced IT Monkey ✭✭✭
    I made this script that uses the API to retrieve the logged in users group membership. It's very quickly made, but hope you get the idea :)

    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
    				hideShowTask(data);
    
    			}
    		},
    		error: function (jqXHR, textStatus, errorThrown) {
    			//debug console.log(errorThrown);
    			//debug console.log(textStatus);
    		}
    	});
    
    
    
    function hideShowTask (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 - task will be shown
    
            console.log("User: " + session.user.Name + " is member of group: " + GroupName)
        }else{
    
            //User is not member of group - Hide task
            console.log("User: " + session.user.Name + " is NOT member of group: " + GroupName)
            $( ".taskmenu li:contains('Resolve Incident')" ).hide() 
        }
    }




  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Hi JD,

    Are you talking about this solution?

    https://community.cireson.com/discussion/451/hide-send-email-link-for-ad-groups-in-incident

    What problems did you have with it? The code from Morten is using the same concept (but better error handling and lovely comments)

    Geoff
  • JD_KeithJD_Keith Customer IT Monkey ✭
    Morten_Meisler & Geoff_Ross - Thank you both for your answers!  It's definitely a step in the right direction for me.  However, I'm still having a bit of trouble.  Basically, I need the opposite of the "Hide Send Email" task and for it to show a custom "Resolve Incident" only to those in certain AD groups (For instance, one is called SM - Bright Spot Admins).  Really what I'm trying to accomplish is to have a group of End Users (Not Analysts) be able to resolve incidents assigned to their support group.  I have a custom form that allows them to edit incidents assigned to them, but they do not have a "Resolve Incident" task on the right - only "Print".  I hope that makes sense and I'm continuing to experiment with both of your solutions in order to try and accomplish this.  I'm just no JavaScript expert :)

    Thanks again!
    JD
  • Morten_MeislerMorten_Meisler Premier Partner Advanced IT Monkey ✭✭✭
    edited October 2016
    A quick fix could be to hide your task for everyone by default. Just put this in top of your script:

    if (IsMemberOfGroup)    {
            //User is member - task will be shown
            </code>$( ".taskmenu li:contains('Resolve Incident')" ).show()<br>
            
        }</code>$( ".taskmenu li:contains('Resolve Incident')" ).hide()</pre>
    
    And then you grant access if the user is a member of your AD group:
    
    <pre class="CodeBlock"><code>



  • JD_KeithJD_Keith Customer IT Monkey ✭
    I'm still unable to get this to work :( I apologize for not being very good at JavaScript, but I'm learning.  This is the code I'm trying to use.  Can you critique please?  Thanks!

    //Start Task

    app.custom.formTasks.add('Incident', "Resolve Incident", function (formObj, viewModel) {
    $( ".taskmenu li:contains('Resolve Incident')" ).hide()

    var GroupName = "ACCU\\SM - BRIGHT SPOT ADMINS"
    $.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
    hideShowTask(data);

    }
    },
    error: function (jqXHR, textStatus, errorThrown) {
    //debug console.log(errorThrown);
    //debug console.log(textStatus);
    }
    });

    function hideShowTask (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 - task will be shown
            $( ".taskmenu li:contains('Resolve Incident')" ).show()

            
        }
    };
    var resolutionenumid = "72674491-02cb-1d90-a48f-1b269eb83602"; //incident resolution category enum
    $.ajax({
    url: "/api/V3/Enum/GetList",
    data: {Id: resolutionenumid},
    type: "GET",
    success: function (resolutiondata) {
    console.log (resolutiondata)
    //Call the ResolveIR Function and send it the IR Resolution Categories Names and Id's
    ResolveIR(resolutiondata);
    }
    });
    //Quick Resolve
    function ResolveIR (resolutiondata){
    //use requirejs to load the HTML template first
    console.log (resolutiondata)
    require(["text!/CustomSpace/customtasks.irresolve.html"], function (template) {
    //make a jQuery obj
    cont = $(template);
    //create a view model to handle the UX
    var _vmWindow = new kendo.observable({
    resolutiondropDownData: resolutiondata,
    resValueChanged : function(e) {
    var dataItem = e.sender.dataItem();
    console.log (dataItem.Text)
    console.log (dataItem.Id)
    },
    resDescription: "",
                okEnabled: false,
                charactersRemaining: "4000",
                textCounter: function () {
                    var maximumLength = 4000;
                    var val = this.resDescription.length;
                    (val > maximumLength) ? this.resDescription.substring(0, maximumLength) : this.set("charactersRemaining", maximumLength - val);
                    (val > 19) ? this.set("okEnabled", true) : this.set("okEnabled", false);
                },
    okClick: function () {
    var resCategoryId = $("#resCategorySelected option:selected").val();
    console.log(resCategoryId);
    var resDescription = this.get("resDescription");

    //They clicked OK now call the Resolve Incident function and send the Resolution Category ID that is selected
    resolveIncident(resCategoryId, resDescription);
    customWindow.close();
    app.lib.mask.apply('Your Incident has been resolved! Please make any other changes that are necessary, then click Save or Apply to complete the process.');
    customWindow.close();
    },
    cancelClick: function () {
    customWindow.close();

    }
    });
     
    //create the kendo window
    customWindow = cont.kendoWindow({
    title: "Resolve Incident",
    resizable: false,
    modal: true,
    viewable: false,
    width: 500,
    height: 400,
    close: function () {
     
    },
    activate: function () {
    //on window activate bind the view model to the loaded template content
    kendo.bind(cont, _vmWindow);
    }
    }).data("kendoWindow");
    //now open the window
    customWindow.open().center();
    });
    }
    // Resolve
    function resolveIncident (categoryid, description) {
    var incident = pageForm.viewModel;
    incident.Status.set("Id", "2b8830b6-59f0-f574-9c2a-f4b4682f1681");
    incident.set("ResolutionDescription",description);
    incident.ResolutionCategory.set("Id",categoryid);
    var uid = session.user.Id;
    var displayname = session.user.Name;
    //set the resolved date
    pageForm.viewModel.set("ResolvedDate", (new Date().toISOString().split(".")[0]));
    //add a new comment to the action log about this being resolved
    incident.AppliesToTroubleTicket = [{
    "ActionType": {
     "Id": "5ca2cfee-6740-1576-540B-ce17222840b8",
     "Name": "Record Resolved"
    },
    "Description": description,
    "EnteredBy": displayname,
    "EnteredDate": new Date().toISOString().split(".")[0],
    "LastModified": new Date().toISOString().split(".")[0],
    "Title": "Record Resolved",
    "Image": "/Content/Images/Icons/ActionLogIcons/recordresolved.png",
    "BillableTime": {
     "BasedId": null,
     "DisplayName": null
    },
    "LastUpdatedDisplay": null
    }];
    incident.RelatesToTroubleTicket = [{
    "ClassTypeId": "eca3c52a-f273-5cdc-f165-3eb95a2b26cf",
    "BaseId": uid,
    "DisplayName": displayname
    }];
    }

    });
    /* ----------------------------------------------- */
    /* -------------- END Resolve Task --------------- */
    /* ----------------------------------------------- */
  • Morten_MeislerMorten_Meisler Premier Partner Advanced IT Monkey ✭✭✭
    edited October 2016
    I haven't looked the whole script through, but you need to put the hide task outside of your custom task eventhandler. Basically, you have two formTask events: one when the user is inside an Incident form, and one for when the user has clicked on your custom task:

    //Inside Incident form:
    app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
        //bind a function to the form ready event
        formObj.boundReady(function () {
    
            //Hide task
           $('[data-bind="click: customFunc"]:contains("Resolve Incident")').hide();
           
    
        });
        return;
    });
    
    //User clicked your task
    app.custom.formTasks.add('Incident', "Resolve Incident", function (formObj, viewModel) {
    //your code
    });
    
    
    Remember also to test in the web browser console (F12), if the hide task code works:
    $( ".taskmenu li:contains('Resolve Incident')" ).hide()

    Edit: And you of course need to have every logic of hiding/showing tasks in the Incident form task, not in the actual custom task. So the ajax calls etc. needs to go in the first formTask and then the actual resolve incident code in the resolve incident custom task.
  • CaterhamITSupportCaterhamITSupport Member Advanced IT Monkey ✭✭✭

    Dear All,

    I am trying to do something similar here. I want to hide "Change Status" on "Tasks" for two technicians or a AD group. I have tried the code above and it doesn't seem to work?

    Thanks

    Daniel

Sign In or Register to comment.