- 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-05-2018 09:36 PM
Hi,
I'm not getting your requirement. Try With below code,
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');
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 12:32 PM
As I change to below code according to your comment it will give the result as commented in the code:
else if (newValue !== oldValue)
{
var f = g_form.getUniqueValue('u_field');
alert('u_field: ' + f); //this does verify that I get the sys_id into the f variable
g_form.setValue('u_field_reference', f); //This does not work
alert('u_field_reference: ' + g_form.getReference('u_field_reference')); //as above row does not set the value this will give back "u_field_reference: [Object Object]"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 11:37 PM
Hi,
Corrected your code. Try with below code,
else if (newValue !== oldValue)
{
var f = g_form.getUniqueValue();
alert('u_field: ' + f); //this does verify that I get the sys_id into the f variable
g_form.setValue('u_field_reference', f); //This does not work
alert('u_field_reference: ' + g_form.getReference('u_field_reference').name); //
(g_form.getReference('u_field_reference').<field from reference table that you want to display>
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 11:53 PM
Thank you. That solves the alert issue but it does not solve why I am not able to set the field "u_field_reference". From what I have read about setting a reference type field it should just be pushing the correct sys_id into that field with g_form.setValue().
As I have verified that I have the sys_id in "f" I don´t have any more clue on what could be wrong with the code i have.