- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2018 02:39 PM
I have a custom table namned "u_anonymisation_fields" with 4 fields and a display value from one of these fields:
- Name: u_table; Type: Table Name
- Name: u_field; Type: Field Name; Dependent field: u_table
- Name: u_field_reference; Type: Reference; Reference to table: sys_dictionary
- Name: u_active; Type: True/False
- Name: Field type; Type: display value with the field "internal_type" dot-walked from the field "Field reference"
What the user should do in this table is to
- choose the table
- choose the field
Then u_field_type should be populated automatically to display what kind of field that has been chosen.
I am trying to do that via a client script that populates the u_field_reference field. But I can´t get my client script to add anything into u_field_reference. No matter if I am removing the setValue on line 17 or not I will never come to the setRef function. I have even tried to remove the setRef with same utterly disappointing result.
I am getting a correct sys_id in the alert for u_field on line 16.
Below is a OnChange Client script that triggers on the field u_field:
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (isLoading)
{
return;
}
if (newValue === '')
{
var clearvalue;
g_form.setValue('u_field_reference',clearvalue);
}
else if (newValue !== oldValue)
{
var f = g_form.getUniqueValue('u_field',setRef);
alert('u_field: ' + g_form.getUniqueValue('u_field'));
g_form.setValue('u_field_reference', f);
alert('u_field_reference: ' + g_form.getReference('u_field_reference'));
}
return;
}
function setRef(f)
{
alert('answer setRef = ' + f);
g_form.setValue('u_field_reference', f);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 02:27 AM
Hi,
If you select field which was from extended table (ex: task) then it will not enter into if. Try with below code,
if (isLoading)
{
return;
}
var clearvalue;
if (newValue === '')
{
alert('newValue was empty');
g_form.setValue('u_field_reference',clearvalue);
}
else if (newValue !== oldValue)
{
var table = g_form.getValue('u_table');
alert('newValue changed to: ' + newValue);
alert('u_table is: ' + table );
var gr = new GlideRecord("sys_dictionary");
gr.addQuery("name", table);
gr.addQuery("element", newValue);
gr.query();
if(gr.next){
alert('gr is: ' + gr.sys_id);
g_form.setValue('u_reference_field',gr.sys_id);//dont leave space while defining 'u_reference_field'
alert(g_form.getReference('u_reference_field').internal_type);
}
else
{
alert('no gr.next');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 12:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 12:27 PM
This is client side where GlideRecord() is not supported.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 11:32 PM
Hi,
For query to database we will use GlideRecord in client side also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 11:45 PM
For me that throws an error that I should not use GlideRecord. when searching error message I get numerous responses that I should not use GlideRecord in wrong place, as I understood it in Client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 12:17 AM
Show me your script once.