Transform Source Script

coodey1
Mega Guru

Issue:  'Assigned to' on the alm_hardware table is being populated with the same user for every record.

 

import field: u_surname (formatted: 'last name'<comma><space>'first name')

target field: Assigned to

 

Source Script:

answer = (function transformEntry(source) {
     if (source.u_surname) {
          var user = new GlideRecord('sys_user');
          user.addQuery('last_name' + ", " + 'first_name', source.u_surname);
          user.query();
          if (user.next()) {
               return user.sys_id;
          } else {
               return "";
          }
     }
})(source);

 

 

 

 

 

1 ACCEPTED SOLUTION

coodey1
Mega Guru

Because my script was populating the field, I thought the query was working.  Then realized it was not not working at all.  Below is the script that works:

 

answer = (function transformEntry(source) {

     if (source.u_surname) {
          var user = new GlideRecord('sys_user');
          x = source.u_surname.split(',')
          user.addQuery('last_name', x[0]);
          user.addQuery('first_name', x[1].trim());
          user.query();
          if (user.next()) {
               return user.sys_id;
          } else {
               return "";
          }
     }
})(source);

View solution in original post

1 REPLY 1

coodey1
Mega Guru

Because my script was populating the field, I thought the query was working.  Then realized it was not not working at all.  Below is the script that works:

 

answer = (function transformEntry(source) {

     if (source.u_surname) {
          var user = new GlideRecord('sys_user');
          x = source.u_surname.split(',')
          user.addQuery('last_name', x[0]);
          user.addQuery('first_name', x[1].trim());
          user.query();
          if (user.next()) {
               return user.sys_id;
          } else {
               return "";
          }
     }
})(source);