The CreatorCon Call for Content is officially open! Get started here.

Client Script: Getting Value of a Field Not On Form

JosephW1
Tera Guru

Hello,

How do I get the value of a field not shown on the current form from within a client script? I'm trying to get the value of incident.child_incidents from a client script for incident.

I've tried "g_form.getValue('child_incidents')" but it returns undefined unless I pull the field onto the form. However, I do not want this field on the form. If I remove the field, it goes back to returning undefined. How do I get around this?

Thanks!

Kind Regards,
Joseph

1 ACCEPTED SOLUTION

Matthew Glenn
Kilo Sage

A few choices here:

  1. Put the field on the form and hide with a UI Policy. 
  2. Retrieve it via a GlideAJAX call
  3. Use a Display Business Rule to put the field value on the scratchpad for use

There may be other methods, but these are the 3 that come to mind.

View solution in original post

6 REPLIES 6

Matthew Glenn
Kilo Sage

A few choices here:

  1. Put the field on the form and hide with a UI Policy. 
  2. Retrieve it via a GlideAJAX call
  3. Use a Display Business Rule to put the field value on the scratchpad for use

There may be other methods, but these are the 3 that come to mind.

Thanks Matthew! That's great, could you give me a working example of GlideAJAX please? I'm having a bit of difficulty with it.

In it's most basic form, this will return the sys_created_on field for an incident

Client Script:

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

    var ga = new GlideAjax('glideAJAXCall'); //must match the name of the script include
    ga.addParam('sysparm_name', 'getFieldValue'); //must match the name of the function
    ga.addParam('sysparm_sys_id', g_form.getUniqueValue()); //passing in incident sys_id
    ga.getXMLAnswer(responseToParse); //function name from below

    function responseToParse(response) {
        //var answer = response;
        alert(response);
    }

}

 

Script Include:

Name: glideAJAXCall

Client Callable: true

var glideAJAXCall = Class.create();
glideAJAXCall.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getFieldValue: function(){
		var sysid = this.getParameter("sysparm_sys_id");
		var gr = new GlideRecord("incident");
		gr.get(sysid);
		return gr.sys_created_on;
		
	},
	
	
    type: 'glideAJAXCall'
});

 

Again, this is in its most basic form, but putting this in should popup the sys_created_on value for the incident. From there, you can do with that value whatever you want. 

If you need some more assistance, you may need to provide a few more details on what table/field you're working with.

Happy to help further if need be.

Thanks Mathew, can you help me to set value ? I tweaked your code and i got the alert message that it successfully set the value but when i see it in list view I don't see the value got actually updated.