Set Assignment group depend on the service Offering

S M
Tera Contributor

Hello Guys.

I am trying to auto populate the assignment groups on the finance form table according to the value on the Service offering filed.

I managed to make it work but after I selecting the Service, the system display the following error message "Error in Validate Assignment Group and Assignee: TypeError; Cannot read property 'sys_id' of undefined". I am quite stack in it and have no idea why this undefined message display, if someone can help with it, that would be grateful.

Here is my client Script and My Script included:

The client Script is:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    try {
                    if (isLoading || newValue == '') {
                                    return;
                    }

                      var incNumber = g_form.getValue('number');
                      if ( incNumber == '' ) {
                                      var service = g_form.getReference('u_bus_service');
                                      var assignment_group = g_form.getReference('assignment_group');

                                      var ga = new GlideAjax('GetSupportGroupFinance');
                                      ga.addParam('sysparm_service_name', service.sys_id);
                                      ga.addParam('sysparm_assignment_group', assignment_group.sys_id);

                                      ga.getXML(GetSupportGroupFinanceParse);
                      }
          }  
          catch (err) {
                              alert('Error in script: Calculate Support Group - Service Field: ' + err.name + '; ' + err.message);                  
              }

              function GetSupportGroupFinanceParse(response) {
                              var answer = response.responseXML.documentElement.getAttribute("answer");

                              g_form.setValue('assignment_group', answer);
                            if(service.u_owned_by =='91c257302b070180bf4aab00f8da1569'){
                                              g_form.setValue('assignment_group', service.support_group); //Finance system
                                }
                              g_form.showFieldMsg('assignment_group', "Assignment group set based on the Service", 'info');
              }
        }

The Script include is:

var GetSupportGroupFinance = Class.create();
GetSupportGroupFinance.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    GetSupportGroupFinance: function () {

          var tableName = this.getParameter('sysparm_table_name');
          var ci = this.getParameter('sysparm_ci_name');
          var service = this.getParameter('sysparm_service_name');
          var assignment_group = this.getParameter('sysparm_assignment_group');
          var caller = this.getParameter('sysparm_user_name');
          var location = this.getParameter('sysparm_location');

          var ciGroup = '';

          var targetCI = new GlideRecord('cmdb_ci');
          targetCI.addQuery('sys_id', ci);
          targetCI.query();

          if (targetCI.next()) {
                var checkGroup = new GlideRecord('sys_user_group');
                checkGroup.addQuery('sys_id', targetCI.supported_by);
                checkGroup.query();
                if (checkGroup.next()) {
                      ciGroup = targetCI.supported_by;
                }
          }

          var serviceGroup = '';

          var targetService = new GlideRecord('cmdb_ci_service'); // query the Business Service table
          targetService.addQuery('sys_id', service);
          targetService.query();

          if (targetService.next()) {
                serviceGroup = targetService.support_group;
                  alert('Service support group is ' + serviceGroup);
          }

          if (serviceGroup != '') {
                          return serviceGroup;
          }

      else {
                        if(tableName == 'u_finance_request') {
                                        return '1e30a392db1b3e00116bf3061d9619cf';
                            }
                          else{
                              return 'd625dccec0a8016700a222a0f7900d06';
                            }
          }
    },

    _privateFunction: function () { // this function is not client callable
    }

});

Thank you,

Shay

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Shay,



I recommend staying away from a script to do this. It's only going to cost you maintenance and testing later. Instead, make this data driven using a data lookup. Easy to build, flexible to change (even in production), and no scripting! And yes, it will modify the values as you change them if you choose that option.



Data lookup rules


S M
Tera Contributor

Hi Chuck.



That can be a good option if the owned_by was a field that I can use on the condition section. but it is not a possible choice on the drop down, so I can not do that in this way. I do need the script to try and manipulate this field.



Thank you for trying to help.


Shay


S M
Tera Contributor

Thank you, that solved the problem