I want make source is phone default for particular groups

Talari Balateja
Tera Expert

Hi,

 

When monitoring team & delivery team members are creating security incident then source should be "phone" by default. it should restrict others to create a source is phone.  

 

EX:

I'm member of monitoring team and I'm creating security incident after click on new button then source should be phone for me and for others it should be none.

 

Regards,

Sanju

2 ACCEPTED SOLUTIONS

@abhishekdalvi 

 

it's showing error, even the part of that particular group and after that I added myself as user from that particular group. then it's working fine but for the existed users it's not working. I'm I created function in right way? why it's showing error like this.

 

 

EXISTING USERS:

TalariBalateja_0-1712208696975.png

 

FOR ME:

TalariBalateja_1-1712208880326.png

 

 

CLIENT SCRIPT:

function onLoad() {

var sysid = g_user.userID; //get current user sysid
var ga = new GlideAjax('sn_si.CheckUserGroup'); //script include name
ga.addParam('sysparm_name', 'getgroup'); //function name
ga.addParam('sysparm_name_sysid', sysid); //passing sysid to server
ga.getXMLAnswer(getGroup);
function getGroup(response) {
if (response == 'true') {
g_form.addInfoMessage('Part of group');
g_form.setValue('contact_type','dlp');
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
} else {
g_form.addInfoMessage(response);
g_form.addInfoMessage('Not Part of group');
g_form.setValue('contact_type', '');//Keep blank
g_form.setReadOnly('contact_type',true); // If you want to restrict the field from changing value
}
}
}

 

SCRIPT INCLUDE:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
       getgroup: function() {
var usersysid = this.getParameter('sysparm_name_sysid');//getting usersysid from client
        var mem = new GlideRecord("sys_user_grmember");
mem.addEncodedQuery('user='+ usersysid+'^group=53a2232a97dc71d047f0b147f053af44^ORgroup=961b73ee47d471d0de549f97536d4300'); // Replace your group sys id in this query
        mem.query();
        if (mem.next()) {
            return true;
        } else {
            return false;
        }
    },
 
    type: 'CheckUserGroup'
});
 
 
FUNTION GET GROUP:
 
TalariBalateja_2-1712208983170.png

 

 

View solution in original post

Hi @Talari Balateja ,

Script is taking the login user. Please try after impersonating the user who is present in that group.

Impersonating an user will solve your issue.

 

Thanks!

Regards,
Abhishek Dalvi

View solution in original post

16 REPLIES 16

Maddysunil
Kilo Sage

@Talari Balateja 

I think you can write before insert BR also you may need to make that field read only and default value as none, Below is the sample BR script:

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the current user is a member of monitoring or delivery team
    var currentUser = gs.getUser();
    var monitoringTeam = currentUser.isMemberOf('monitoring_team');
    var deliveryTeam = currentUser.isMemberOf('delivery_team');

    if (monitoringTeam || deliveryTeam) {
        // Set source to "phone"
        current.source = 'phone';
    }
})(current, previous);

 

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Hi @Maddysunil,

 

I have tried but it's not working.

 

Regards,

Sanju.

Please share your script

(function executeRule(current, previous /*null when async*/) {
// Check if the current user is a member of monitoring or delivery team
var currentUser = gs.getUser();
var monitoringTeam = currentUser.isMemberOf('Phone Monitoring Team');
var deliveryTeam = currentUser.isMemberOf('Secure Delivery Team');

if (monitoringTeam || deliveryTeam) {
// Set source to "phone"
current.contact_type = 'phone';
}
})(current, previous);