POP location

Anusha Medharam
Tera Contributor

I have configured a field on the sn customerservice task form where the reference is to the cmdb ci site table, and you want to automatically populate the Assignment Group field based on the selected site, In site has one attribute support group ,I have to populate that field value into Assignment group.

4 REPLIES 4

Srinivasa1
Tera Expert

Achieving this task can be approached through various methods such as Client script & GlideAjax, Assignment rule, or Business rule. For example, you can create a "before" Business rule on the task table with a condition based on CMDB changes. Here's a sample script:
if (current.cmdb_ci.support_group)
{

    current.assignment_group = current.cmdb_ci.support_group.sys_id;
}

Let me know how to write Client script & GlideAjax.

Srinivasa1
Tera Expert

Client Script:
Type: On change
Filed: CMDB
UI Type: All
Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 
    if (isLoading) {
        return;
    }
    if (newValue === '') {
        g_form.setValue("assignment_group", "");
        return;
    }
    var ga = new GlideAjax('assignmentRuleUtil'); // HelloWorld is the script include class 
    ga.addParam('sysparm_name', 'populateAssignmentGroup'); // helloWorld is the script include method 
    ga.addParam('sysparm_ci', newValue); // Set parameter sysparm_user_name to 'Bob' 
    ga.getXML(parseResponse);
 
    function parseResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
        if(answer){
g_form.setValue("assignment_group", answer);
}
    }
 
 
    //Type appropriate comment here, and begin script below
 
}



New script include:
Name: assignmentRuleUtil
client callable: True
var assignmentRuleUtil = Class.create();
assignmentRuleUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
    populateAssignmentGroup: function() {
        var ci = this.getParameter("sysparm_ci");
        var ciGR = new GlideRecord('cmdb_ci');
        if(ciGR.get(ci)){
if(ciGR.support_group){
return ciGR.support_group.sys_id;
}
}
},
 
type: 'assignmentRuleUtil'
});

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Anusha Medharam ,
I trust you are doing great.
Please find the client script and script include for the same as given below:
Script include :

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

    getSupportGroup: function() {
        var site = this.getParameter('site');

        // Query the CMDB CI Site table to get the support group for the selected site
        var siteGr = new GlideRecord('cmdb_ci_site');
        if (siteGr.get(site)) {
            return siteGr.getValue('support_group');
        }

        return ''; // If support group is not found, return empty string
    }
});

 

Client script :

// Client script to populate Assignment Group based on selected site
function onChangeSite() {
    var site = g_form.getValue('cmdb_ci'); // Assuming 'cmdb_ci' is the field name for the site reference

    // Call GlideAjax to get the support group for the selected site
    var ga = new GlideAjax('GetSupportGroup');
    ga.addParam('sysparm_name', 'getSupportGroup');
    ga.addParam('site', site);
    ga.getXMLAnswer(populateAssignmentGroup);
}

function populateAssignmentGroup(response) {
    var assignmentGroup = response;

    // Set the value of Assignment Group field
    g_form.setValue('assignment_group', assignmentGroup);
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi