Error Ljava.lang.String;@

Vimal Priya
Giga Guru

Hi All,

I am getting values from slush bucket and checking in GlideRecord .but it throws an error Ljava.lang.String;@

Any idea??

Moreover https://community.servicenow.com/thread/164501?q=Error%20Ljava.lang.String;@ and my issue is same

my Scripts are below,

Script Include:

var CtaskSelectAjax = Class.create();

CtaskSelectAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  getctask: function() {

  //var arr=[];

  var cr=this.getParameter('sysparm_num');

  var gr = new GlideRecord("change_task");

  gr.orderBy('number');

  //gr.addQuery('active',true);

  gr.addQuery('change_request', cr);

  gr.query();

  //Add the available groups to select from

  while (gr.next()) {

  var item = this.newItem();

  item.setAttribute('value', gr.getValue('sys_id'));

  item.setAttribute('text', gr.getValue('number'));

  //arr.push(gr.getValue('sys_id'));

  //gs.log('test values'+arr.push(gr.getValue('sys_id')));

  }

  //return arr.push(gr.getValue('sys_id'));

  },

  //Take a taskID and group sys_id values and add 'sysapproval_group' records

  CtaskAdd: function() {

  var taskID = this.getParameter('sysparm_taskID');

  var answ=this.getParameter('sysparm_ansValue');

  gs.log('log answ values'+answ);

//var values = this.getParameter('sysparm_values').split(",");//caused an error Ljava.lang.String;@ so tried with replace function it also doesnot works

  var values = this.getParameter('sysparm_values');

  values = values.toString().replace(/,/g,"~|~");

  //var val=[];

  var val = '';

  val = values.toString().split("~|~");

  gs.log('log values'+values);

  gs.log('log_values'+val);

  //Iterate through the group sys_id values

  for(var x in val)

  {

  var ct= new GlideRecord('change_task');

  ct.addQuery('change_request',taskID);

  ct.addEncodedQuery('sys_idIN'+values);

  ct.query();

  gs.log('Row Count'+ct.getRowCount());

  while(ct.next())

  {

  var chg_tsk = new GlideRecord('change_task');

  chg_tsk.initialize();

  chg_tsk.u_copied_from_cr=taskID;

  chg_tsk.change_request=answ;

  chg_tsk.state = -5;

  chg_tsk.cmdb_ci = ct.cmdb_ci;

  chg_tsk.u_change_task_type = ct.u_change_task_type;

  chg_tsk.short_description = ct.short_description;

  chg_tsk.description = ct.description;

  chg_tsk.assignment_group = ct.assignment_group;

  chg_tsk.insert();

  }

  }

  },

  type: 'CtaskSelectAjax'

});

Client Script on UI Page:

function ProceedToClone()

{

  var arr = "";

  jQuery("#clone_change input[type=checkbox]:checked").each(function()

  {

  arr = arr + "," +jQuery(this).attr('name').split(".")[1];

  });

  var lChNum = jQuery("#change_number").val();

  var ga = new GlideAjax('MPI_AJAX_Util');

  ga.addParam('sysparm_name','cloneChange');

  ga.addParam('sysparm_change_num',lChNum);

  ga.addParam('sysparm_field_name',arr);

  ga.getXML(CloneChange);

  var changeNum = g_form.getValue('change_request.number');

  var values = slush.getValues(slush.getRightSelect());

  //Get the sys_id of the current record

  var taskID = g_form.getUniqueValue();

  alert(taskID);

  //Make sure we have at least one selection

  if(values == ''){

  alert("At least one group must be selected");

  return;

  }}

function CloneChange(response) {

  var taskID=g_form.getUniqueValue();

  alert(taskID+'taskID');

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

  var URL = "https://"+getMessage('MPI_Instance_Name')+".service-now.com/change_request.do?sys_id=" + answer;

  window.location.href = URL;

  CtaskAjaxFunction(answer,taskID);

}

  function CtaskAjaxFunction(ans,tskId)

  {

  var values = slush.getValues(slush.getRightSelect());

  alert('VALUES:: '+values);

  alert(ans+'cr');

  var ajax = new GlideAjax('CtaskSelectAjax');

  ajax.addParam('sysparm_name', 'CtaskAdd');

  ajax.addParam('sysparm_taskID', tskId);

  ajax.addParam('sysparm_ansValue', ans);

  ajax.addParam('sysparm_values', values);

  ajax.getXML(addCtaskResponse);

}

function addCtaskResponse(response){

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

  //GlideDialogWindow.get().destroy();

  //GlideList2.get('').setFilterAndRefresh('');

  //return false;

}

addLoadEvent(function(){

  //Load the groups when the form loads

  slush.clear();

  var values = slush.getValues(slush.getRightSelect());

  //Get the sys_id of the current record

  var taskID = g_form.getUniqueValue();

  alert(taskID+'CR');

  var ajax = new GlideAjax('CtaskSelectAjax');

  ajax.addParam('sysparm_name', 'getctask');

  ajax.addParam('sysparm_num',taskID);

  ajax.addParam('sysparm_values', values);

  ajax.getXML(loadResponse);

  return false;

});

//Called when we get a response from the 'addLoadEvent' function

function loadResponse(response){

  //Process the return XML document and add groups to the left select

  //var lChNo = jQuery("#change_number").val();

  var xml = response.responseXML;

  var e = xml.documentElement;

  var items = xml.getElementsByTagName("item");

  if(items.length == 0)

  return;

  //Loop through item elements and add each item to left slushbucket

  for (var i = 0; i < items.length; i++) {

  var item = items[i];

  slush.addLeftChoice(item.getAttribute('value'), item.getAttribute('text'));

  alert('Slush values'+slush.addLeftChoice(item.getAttribute('value'), item.getAttribute('text')));

  }

}

function ProceedToCancel()

{

  GlideDialogWindow.get().destroy();

}

Please provide your solutions.

Thanks in adavnce.

1 ACCEPTED SOLUTION

sateesh5
Tera Contributor

I would suggest you to use split before your iterate. Probably that is what your logic suppose to work like.


It seems you are iterating this line(contains split), which splits the string and creates an array and then again in next iteration, it tries to split the undefined/null object which might cause the problem.


View solution in original post

9 REPLIES 9

sateesh5
Tera Contributor

I would suggest you to use split before your iterate. Probably that is what your logic suppose to work like.


It seems you are iterating this line(contains split), which splits the string and creates an array and then again in next iteration, it tries to split the undefined/null object which might cause the problem.


Sakshi14
Giga Expert

Hey Vimal,

I know this is an old post, and the problem is probably already resolved for you, but I ran into the same issue recently, and had really scour the net to find a relevant solution. 

Hence, posting the solution for the benefit of anybody else who might encounter the same issue:

This error comes because the value being returned is a Java string, and we are trying to process it as a javascript string. So the solution is to convert it into a JavaScript String using the following syntax:

var newString= String(oldString).valueOf();

 

Hope this helps!

 

Thanks
Sakshi

Hi Sakshi,

I am having the exact issue.  Using glideAjax in client script.  Then script include has this code:

var mouse = this.getParameter('sysparm_mouse');
		mouse = mouse.split(',');
		gs.log('Laurie says mouse is ' + mouse);

 

And the log shows:  Information Laurie says mouse is [Ljava.lang.String;@c09a8a

I checked and the sys_id of the mouse is correct from client side

function onSubmit() {
	var mouseOp = g_form.getValue('mouse_options');
	mouseOp = mouseOp+',Mouse';
	alert(mouseOp);
	var keyOp = g_form.getValue('keyboard_options');
	keyOp = keyOp+',Keyboard';
	var dsOp = g_form.getValue('ds_options');
	dsOp = dsOp+',Docking';
	var NetCables = g_form.getValue('network_cable_options');
	NetCables = NetCables+',Cables';
	var laptopBags = g_form.getValue('laptop_bag_options');
	laptopBags = laptopBags+',Laptop Bags';
	var monitor = g_form.getValue('monitor_options');
	monitor = monitor+',Monitor';
	//var software = g_form.getValue('software_options');
	//software = software+',Software';
	//var mand1 = g_form.getValue('mand_item1');
	//mand1 = mand1+',Mand1';
	//var mand2 = g_form.getValue('mand_item2');
	//mand2 = mand2+',Mand2';
	//alert(window.location.href);
	//alert(location.href);
	//if(mouseOp != '' || keyOp != '' || dsOp != ''){ // Call script include only when one of the option is selected..
		var func = new GlideAjax('FPCatalogFunctions');
		func.addParam('sysparm_name','customAddItems');
		func.addParam('sysparm_url',window.location.href);
		func.addParam('sysparm_mouse',mouseOp);
		func.addParam('sysparm_keyboard',keyOp);
		func.addParam('sysparm_dStation',dsOp);
		func.addParam('sysparm_cables',NetCables);
		func.addParam('sysparm_laptopbag',laptopBags);
		func.addParam('sysparm_monitors',monitor);
		//func.addParam('sysparm_software',software);
		//func.addParam('sysparm_mand1',mand1);
		//func.addParam('sysparm_mand2',mand2);
		func.getXML(getValues);
		
		
		//setTimeout(function(){waitSomeTime();},3000);
			return false;
			
		}
		function getValues(response) {
			
			var answer = response.responseXML.documentElement.getAttribute("answer");
			alert(answer);
			
		}

 

Any ideas?  

Thank you in advance.

Laurie

[Ljava.lang.String;@c09a8a means that is an array of type string. So you do not need to split it any more.

Three years ago you commented on a two year old post and I just want to thank you for that!  This one simple line helped me so much!