Need help in scripting

jayaprakash1998
Tera Contributor

Requirement:

1. Create a checkbox 'primary support' in group table.

2. In Incident form if assignment group is selected in incident form and if that assignment group check box primary support is true then show an alert message.

 

I have created the checkbox and writtern script to find the name of the assignment group from incident

 

I have no idea how to find that assignment group checkbox value from incident form script.

 

Can anyone help please ?

 

My script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var group = g_form.getDisplayBox('assignment_group').value;
    alert(group);
}
4 ACCEPTED SOLUTIONS

Clara Lemos
Mega Sage
Mega Sage

Hi @jayaprakash1998 ,

 

You can try the following for you script :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var primarySupport = g_form.getReference('assignment_group').u_primary_support; // gets the value of the primary support checkbox ( true or false)
   if(primarySupport=='true'){ // if primary Support is true show alert
	alert(g_form.getReference('assignment_group').name); // alert with the name of the assingment group 
   } 
}

 

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

View solution in original post

Danish Bhairag2
Tera Sage
Tera Sage

Hi @jayaprakash1998 ,

 

You can achieve this by creating an onChange client script & a script include please copy the below code

 

Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

 

    // Use GlideAjax to check if the primary support checkbox is true for the selected Assignment Group

    var ga = new GlideAjax('CheckPrimarySupport');

    ga.addParam('sysparm_name', 'checkPrimarySupport');

    ga.addParam('sysparm_assignment_group', newValue);

    ga.getXMLAnswer(function(response) {

        if (response == 'true') {

            alert('This Assignment Group is marked as Primary Support.');

       

}

    });

}

 

Script Include:

Client callable : true

 

var CheckPrimarySupport = Class.create();

 

CheckPrimarySupport.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkPrimarySupport: function() {

        var assignmentGroup = this.getParameter('sysparm_assignment_group');

 

        var groupGR = new GlideRecord('sys_user_group');

        if (groupGR.get('sys_id', assignmentGroup) && groupGR.primary_support) {

            return 'true';

        } else {

            return 'false';

        }

    },

 

    type: 'CheckPrima

rySupport'

});

 

Thanks,

Danish

 

View solution in original post

Prince Arora
Tera Sage
Tera Sage

@jayaprakash1998 

 

Can you try this:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var result = g_form.getReference('assignment_group', myData);
   function myData(result){
      if(result.u_primary_support+"" == "true"){
                alert(result.name);
            }
}
}

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

Shivam Techlene
Tera Guru

Hello @jayaprakash1998,

 

You can achieve this functionality using multiple ways.

1. Using getReference() inside an OnChange client script. which is also suggested by @Clara Lemos@Prince Arora.

2. Using Onchange client script and a script include combined. The scripts are given below.

 

Client Script:

Table: Incident

Type: OnChange

Field Name: Assignment Group

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('AssignmentCheckbox'); //Script Include Name
    ga.addParam('sysparm_name', 'checkAssignmentCheckbox'); //Script Include function name
    ga.addParam('group', newValue);
	ga.getXMLAnswer(GetResponse); 

    function GetResponse(response) {
        if (response == 'true') {
            alert('Group is primary group');
        }
    }
}

 

 

Script Include:

Client Callable: true

 

var AssignmentCheckbox = Class.create();
AssignmentCheckbox.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkAssignmentCheckbox: function() {
        var group = this.getParameter('group');
        var gr = new GlideRecord('sys_user_group');
        gr.addQuery('sys_id', group);
        gr.query();
        if (gr.next()) {
            if (gr.getValue('u_primary_support') == true)
                return 'true';
            else
                return 'false';
        }
    },
	
    type: 'AssignmentCheckbox'
});

 

 

Please Mark my answer helpful and correct if it helps to achieve your requirement.

 

Thanks & Regards,
Shivam Jaiswal

View solution in original post

7 REPLIES 7

Clara Lemos
Mega Sage
Mega Sage

Hi @jayaprakash1998 ,

 

You can try the following for you script :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var primarySupport = g_form.getReference('assignment_group').u_primary_support; // gets the value of the primary support checkbox ( true or false)
   if(primarySupport=='true'){ // if primary Support is true show alert
	alert(g_form.getReference('assignment_group').name); // alert with the name of the assingment group 
   } 
}

 

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

Danish Bhairag2
Tera Sage
Tera Sage

Hi @jayaprakash1998 ,

 

You can achieve this by creating an onChange client script & a script include please copy the below code

 

Client Script:

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

 

    // Use GlideAjax to check if the primary support checkbox is true for the selected Assignment Group

    var ga = new GlideAjax('CheckPrimarySupport');

    ga.addParam('sysparm_name', 'checkPrimarySupport');

    ga.addParam('sysparm_assignment_group', newValue);

    ga.getXMLAnswer(function(response) {

        if (response == 'true') {

            alert('This Assignment Group is marked as Primary Support.');

       

}

    });

}

 

Script Include:

Client callable : true

 

var CheckPrimarySupport = Class.create();

 

CheckPrimarySupport.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkPrimarySupport: function() {

        var assignmentGroup = this.getParameter('sysparm_assignment_group');

 

        var groupGR = new GlideRecord('sys_user_group');

        if (groupGR.get('sys_id', assignmentGroup) && groupGR.primary_support) {

            return 'true';

        } else {

            return 'false';

        }

    },

 

    type: 'CheckPrima

rySupport'

});

 

Thanks,

Danish

 

Prince Arora
Tera Sage
Tera Sage

@jayaprakash1998 

 

Can you try this:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var result = g_form.getReference('assignment_group', myData);
   function myData(result){
      if(result.u_primary_support+"" == "true"){
                alert(result.name);
            }
}
}

 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Shivam Techlene
Tera Guru

Hello @jayaprakash1998,

 

You can achieve this functionality using multiple ways.

1. Using getReference() inside an OnChange client script. which is also suggested by @Clara Lemos@Prince Arora.

2. Using Onchange client script and a script include combined. The scripts are given below.

 

Client Script:

Table: Incident

Type: OnChange

Field Name: Assignment Group

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('AssignmentCheckbox'); //Script Include Name
    ga.addParam('sysparm_name', 'checkAssignmentCheckbox'); //Script Include function name
    ga.addParam('group', newValue);
	ga.getXMLAnswer(GetResponse); 

    function GetResponse(response) {
        if (response == 'true') {
            alert('Group is primary group');
        }
    }
}

 

 

Script Include:

Client Callable: true

 

var AssignmentCheckbox = Class.create();
AssignmentCheckbox.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkAssignmentCheckbox: function() {
        var group = this.getParameter('group');
        var gr = new GlideRecord('sys_user_group');
        gr.addQuery('sys_id', group);
        gr.query();
        if (gr.next()) {
            if (gr.getValue('u_primary_support') == true)
                return 'true';
            else
                return 'false';
        }
    },
	
    type: 'AssignmentCheckbox'
});

 

 

Please Mark my answer helpful and correct if it helps to achieve your requirement.

 

Thanks & Regards,
Shivam Jaiswal