How to reference parent field in child client script

Elizabeth26
Tera Contributor

I need to reference a parent field on a child client script.

It is not working.

 

var category = g_form.getValue('x_table_name.parent_case.field_name');

1 ACCEPTED SOLUTION

Ian Mildon
Tera Guru

Have you tried a "getReference" script function yet?

 

I recently used the following script in an onChange Client Script for when the Category field is changed and it then checks values on the Category record. Actually this one runs two separate getReference lookups on two different tables.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
       return;
    }
 
    if (newValue && g_form.getValue('proposal_type', 2)) {
        checkIfEpic();
    }

    function checkIfEpic() { //* first reference lookup
        g_form.getReference('category', doAlert);
    }
    
    function doAlert(getCat) {
        if (getCat.getValue('parent') == '04982248db357680ec5c3c00ad961962' || getCat.getValue('parent') == '93b2fe57db55b280deda327e9d961997') {
            g_form.setReadOnly('category', true);
            g_form.setReadOnly('template_name', true);
            getDesc();
        }
    }
    
    function getDesc() { //* second reference lookup
        g_form.getReference('std_change_producer', doAlert2);
    }

    function doAlert2(getDesc) {
        g_form.setValue('short_description', getDesc.short_description);
        g_form.setReadOnly('short_description', true);
    }
 } 

View solution in original post

4 REPLIES 4

Prince Arora
Tera Sage
Tera Sage

@Elizabeth26 

 

Not getting the statement completely!

 

Still let me try to answer it, if you want to get parent field in child table client script, please try:

 

g_form.getValue("NAME_OF_THE_FIELD_IN_PARENT_TABLE");

 

because that field is the part of child table also!

 

If it has not answered your query please take a look at THIS 

 

If still your question is different, please explain it in little more details with screenshot 🙂

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

 

 

I have tried using as you suggested above - which isn't working.

I have tried the example I put in a different script which does work but not sure why it won't work here.

I am currently looking at that other article.

Bert_c1
Kilo Patron

Hi,

 

'x_table_name.parent_case.field_name' is not a form field I guess.  You can use GlideAJax in the client script, along with a script include, to get the value.

Ian Mildon
Tera Guru

Have you tried a "getReference" script function yet?

 

I recently used the following script in an onChange Client Script for when the Category field is changed and it then checks values on the Category record. Actually this one runs two separate getReference lookups on two different tables.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
       return;
    }
 
    if (newValue && g_form.getValue('proposal_type', 2)) {
        checkIfEpic();
    }

    function checkIfEpic() { //* first reference lookup
        g_form.getReference('category', doAlert);
    }
    
    function doAlert(getCat) {
        if (getCat.getValue('parent') == '04982248db357680ec5c3c00ad961962' || getCat.getValue('parent') == '93b2fe57db55b280deda327e9d961997') {
            g_form.setReadOnly('category', true);
            g_form.setReadOnly('template_name', true);
            getDesc();
        }
    }
    
    function getDesc() { //* second reference lookup
        g_form.getReference('std_change_producer', doAlert2);
    }

    function doAlert2(getDesc) {
        g_form.setValue('short_description', getDesc.short_description);
        g_form.setReadOnly('short_description', true);
    }
 }