To check assignment group condition on a widget

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have a widget which contains a reopen button inside it.

 

I want to show an error msg when user clicks on that button when its assigned to xyz group. I want to restrict that action when its assigned to this group.

 

Here is the server script for that.

 

if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
        incidentGr.state = global.IncidentState.IN_PROGRESS;
        incidentGr.comments = "Reason for rejection: " + input.rejectReason; //Line added for fixing INC3257360
        data.isIncidentReopened = incidentGr.update();
        gs.addInfoMessage(gs.getMessage("Request reopened"));
    }
if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
        if (data.assignment_group == 'sys_id')
            current.setAbortAction(true);
        gs.addErrorMessage(gs.getMessage('Incident cannot be reopened as its assigned to command centre'));
    }
 
But its showing that error msg everytime and reopening the incident.
1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Poorva Bhawsar ,

 

You can use the below script: 

if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
if (incidentGr.assignment_group.getDisplayValue() ==="Assignment Group Name") { // replace with actual group name
gs.addErrorMessage('Incident cannot be reopened as its assigned to command centre');
}else {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
        incidentGr.state = global.IncidentState.IN_PROGRESS;
        incidentGr.comments = "Reason for rejection: " + input.rejectReason; //Line added for fixing INC3257360
        data.isIncidentReopened = incidentGr.update();
        gs.addInfoMessage(gs.getMessage("Request reopened"));
    }
}

 

You can replace 'Assignment Group Name' with actual group name in line 2

 

Please mark as Accepted Solution & hit helpful !!!  

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

3 REPLIES 3

Anirudh Pathak
Mega Sage

Hi @Poorva Bhawsar ,

Does your widget contain a list of incidents and each incident have a reopen button beside it?

If that's the case then, you will need to write a function inside "client controller" which will get called "on-click" of reopen button, pass the incident "sys_id" from that function to server side and then show error message just for that incident by checking assignment group condition.

This is what currently i have in my client controller for reopen button.

 

$scope.reopenIncident = function() {
        spModal.open({
            title: 'Please confirm if you want to reopen this incident.',
            message: 'Please enter reason for re-opening this incident:',
            input: true,
             buttons: [
                {label:'✘ ${No}', cancel: true},
                {label:'✔ ${Yes}', primary: true}
            ]
        }).then(function(name) {
        $scope.data.rejectReason = name;
        $scope.data.action = 'reopenIncident';
        $scope.server.update(init).then(function(response){
                    if (response.isIncidentReopened)
                        spAriaUtil.sendLiveMessage(c.reopenedIncidentMsg);
                });
            $scope.$emit('focusOnActions', {"isFocusRequired": true});
        })
    };

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Poorva Bhawsar ,

 

You can use the below script: 

if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
if (incidentGr.assignment_group.getDisplayValue() ==="Assignment Group Name") { // replace with actual group name
gs.addErrorMessage('Incident cannot be reopened as its assigned to command centre');
}else {
        incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
        incidentGr.state = global.IncidentState.IN_PROGRESS;
        incidentGr.comments = "Reason for rejection: " + input.rejectReason; //Line added for fixing INC3257360
        data.isIncidentReopened = incidentGr.update();
        gs.addInfoMessage(gs.getMessage("Request reopened"));
    }
}

 

You can replace 'Assignment Group Name' with actual group name in line 2

 

Please mark as Accepted Solution & hit helpful !!!  

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)