How to get the refernce/choice field value using Onload and Onchange CS ?

PP12
Giga Contributor

Referring to a thread i tried g_form.getDisplayBox('field_name').value; 

but it didn't work in onChange Cs whereas in onLoad it worked for some field, not for all.

getValue() -- gives you the value not the name.

getDisplayValue() is not recommended for client side So,

can anyone give me example for both onload and onchange cs , how to get the value of reference/choice field and display in an alert for testing purpose?

no need to use if condition just simply get the the value and display in alert.

 

 

Thank You.

1 ACCEPTED SOLUTION

Hello PP, 

Missed your previous reply, my bad. 

Ok Let me share you a client script and a script include with the same what you wanted to do 

Based on your script include code what you are doing is exactly correct. just you need to add a couple of additional parameters to pass the values from the client script to your script include so that it can process and give you back the results 

Client Script:

function onLoad(){

var ga = new GlideAjax('clientsidecall');

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

ga.addParam('sysparm_asg_grp',g_form.getValue('assignment_group');

ga.addParam('sysparm_asg_to',g_form.getValue('assigned_to;);

ga.getXML(val1);

 

function val1(response){

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

alert(answer);

}

}

 

Client Script :

var ClientsideCall = Class.create();
ClientsideCall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
Getvalue : function(){
var at = this.getParameter('sysparm_asg_to');
var asg_group = this.getParameter('sysparm_asg_grp');
return at+","+asg_group;
},
type: 'ClientsideCall'
});

 

Hope that helps 

 

For passing multiple values back to the client script from script include you can also use JSON but the thing you are looking for should work with what i have provided above

 

Mark this response as correct if that really helps 

Thanks,

Siva

 

 

 

View solution in original post

21 REPLIES 21

PP12
Giga Contributor

so that means server side methods can be used while writing the script..

 

and one thing i am trying a scenario that -

script include -

find_real_file.png

Client script - 

find_real_file.png

 

Whenever i am loading the form i am getting null -

find_real_file.png

 

getValue and getDisplayValue isn't working for me and in options also it not showing.

how to get the values of a refernce or choice field in this SI ?

Below is the sample code

var ga = new GlideAjax('TestEmail');
	ga.addParam('sysparm_name','getHRCaseEmailTypes');
	ga.addParam('sysparm_type', 'global');
	ga.addParam('sysparm_value', newValue);
	ga.getXMLAnswer(getResponse);
	function getResponse(response) {
		if(response.length) {
			var typeList = response.split(',');
			for (i = 0; i < typeList.length; i++) {
				g_form.removeOption('u_banner_email_type', typeList[i]);
			}
		}
	}

getHRCaseEmailTypes: function() {
		var ga = new GlideRecord('u_hr_case_banner_images');
		var paramType = this.getParameter('sysparm_type');
		var paramValue = this.getParameter('sysparm_value');
		
	}

PP12
Giga Contributor

sorry but i don't get it exactly.

I want to know why its not getting value from SI in my case and displaying null in alert?

😞

Share your details by mail.

I would highly encourage you to go through this link which explains how glideajax call works. Server and client side responsibilities

https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side

 

There are couple of syntax errors in the scripts

  • Server script: gs. do not have getValue methods. You need to do glide query
  • Client script: If you would like pass assigned_to and assignment_group value to server, you need to add sysparm parameters to client script and pass values