Split the string from description and get the id and set it in the name and location field.

aladpereira
Mega Expert

Hi all,

Split the string from description and get the id and set it in the name and location field. any help in this will be highly appreciated.

Business rule:

function onBefore(current, previous) {

      //This function will be automatically called when this rule is processed.

      //var desc = current.description;

      var desc = "EMPLOYEE ID : 125316   Lan ID : test ";

      var splited=desc.split(":");

      var str1 = splited[1];

      var str = str1.split("Lan");

      var mystr = str[0];

      gs.addInfoMessage(mystr);

      var qry = new GlideRecord('sys_user');

      //qry.addQuery('user_name',mystr);

      qry.addEncodedQuery('user_name='+mystr);                       // if i give the id directly here its working fine.

      qry.query();

      if(qry.next())

              {

              gs.addInfoMessage("first");

              current.u_user=qry.sys_id;

              current.u_location=qry.location;

              gs.addInfoMessage("Sucessfull");

      }

}

Regards,

Alad.

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage
var desc = "EMPLOYEE ID : 125316  Lan ID : test ";
var initialValue = desc.split(":");
var userID = (initialValue[1].replace('Lan ID','')).trim();
var lanID = initialValue[2].trim();

user id  will contain the value needed. Use it in your code


View solution in original post

2 REPLIES 2

Deepak Ingale1
Mega Sage

Hi Anto,



user_name is employee id in your case? if it is so, your code should be



qry.addQuery('user_name',mystr.toString());



just try with this line and check.


Kalaiarasan Pus
Giga Sage
var desc = "EMPLOYEE ID : 125316  Lan ID : test ";
var initialValue = desc.split(":");
var userID = (initialValue[1].replace('Lan ID','')).trim();
var lanID = initialValue[2].trim();

user id  will contain the value needed. Use it in your code