populate Assignment group based on the selected service/service offering

soumya19
Tera Contributor

Hi,

 

I have a requirement to populate the assignment group based on the service selected.

  • if there is no value in assignment group field, populate the assignement group with the support group of service.
  • If there is already a value in assignement group then it should ask for confirmation.
  • and if the support group correlation Id starts with "I-" or "V-", it should not update the assignment group, else it should update the assignement group.

can anyone help me to achieve this ?

 

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var servicename = g_form.getValue('business_service');
var offering = g_form.getValue('service_offering');
var assignmentgrp = g_form.getValue('assignment_group');
if (servicename != '' && offering == '') {
if (assignmentgrp == '') {
service();
} else {
var ans = confirm('Are you sure want to update the assignment group with service support group');
if (ans == true) {
service();
}
}
}

function service() {
var getdata = new GlideAjax('AutopopulateAssignmentgroup');
getdata.addParam('sysparm_name', 'Getservicesupportgroup');
getdata.addParam('sysparm_service', servicename);
getdata.getXML(result);
}

function result(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group', answer);
}
}

 

Script Include:

 

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

Getservicesupportgroup: function(){
var servicename = this.getParameter('sysparm_service');
var getgrp = new GlideRecord('cmdb_ci_service');
getgrp.addQuery('sys_id',servicename);
getgrp.query();
if(getgrp.next()){
var supportgroup = getgrp.getValue('support_group').toString();
if(supportgroup.u_correlation_id.indexOf('I-')==0)
return;
else
return supportgroup;
}
},

type: 'AutopopulateAssignmentgroup'
});

1 ACCEPTED SOLUTION

I think you could simplify it this way

 

Getservicesupportgroup: function(){
var servicename = this.getParameter('sysparm_service');      //sys_id of service
var getgrp = new GlideRecord('cmdb_ci_service');
getgrp.get(servicename);     //goes straight to the service glide record
if(getgrp){          //if there is a glide record
    var supGroupCorrId = getgrp.support_group.u_correlation_id.getDisplayValue();
    if(supGroupCorrId.indexOf('I-')==0 || supGroupCorrId.indexOf('V-')==0)
        return;
    else
        return getgrp.support_group;   //sys_id of the support group
}

If I helped you with your case, please click the Thumb Icon and mark as Correct.


View solution in original post

5 REPLIES 5

Sebas Di Loreto
Kilo Sage
Kilo Sage

@soumya19 

I think you have an error in your logic.

Line "var supportgroup = getgrp.getValue('support_group').toString();" will give you the sys_id of the support_group of the service and you CANNOT dot walk it later like you do in the next line.

All you care at that point is to check if the correlation_id of that support group starts with I- or V-, then the right code should be:

 

 

var getgrp = new GlideRecord('cmdb_ci_service');
getgrp.addQuery('sys_id',servicename );
getgrp.query();
if(getgrp.next()){
    var supGroupCorrId = getgrp.support_group.u_correlation_id.getDisplayValue();
    if(supGroupCorrId.indexOf('I-')==0 || supGroupCorrId.indexOf('V-')==0)
        return;
    else
        return getgrp.support_group;   //sys_id of the support group
}

 

 

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


I think you could simplify it this way

 

Getservicesupportgroup: function(){
var servicename = this.getParameter('sysparm_service');      //sys_id of service
var getgrp = new GlideRecord('cmdb_ci_service');
getgrp.get(servicename);     //goes straight to the service glide record
if(getgrp){          //if there is a glide record
    var supGroupCorrId = getgrp.support_group.u_correlation_id.getDisplayValue();
    if(supGroupCorrId.indexOf('I-')==0 || supGroupCorrId.indexOf('V-')==0)
        return;
    else
        return getgrp.support_group;   //sys_id of the support group
}

If I helped you with your case, please click the Thumb Icon and mark as Correct.


Thank you...! Adding one line of code in client script resolved my issue.

if(answer) //Added this in callback function.

@soumya19 

Correct. I was going to answer something like that but you beat me.

That logic is part of the callback function on deciding what to do with the answer.

The main issue was on the script include. 

I am glad you figured it out.


If I helped you with your case, please click the Thumb Icon and mark as Correct.