Need help on client script both on load and on change

Bird1
Mega Sage

I got a requirement to create client script both onload and on change.

If language is 'Chinese' && Knowledge base is 'Knowledge' the Ownership group should auto populate.

find_real_file.png

 

I tried to write the onload script (need a new record due to we use dynamic translation from Eng to Chinese) but not work.(not auto populate the ownership group field)

 

Script (on load)

function onLoad() {
   //Type appropriate comment here, and begin script below
  
    if ((g_form.isNewRecord()) && (g_form.getValue('language') == 'zh') && (g_form.getValue ('kb_knowledge_base') == 'dfc19531bf2021003f07e2c1ac0739ab')){
    g_form.setValue('ownership_group','6208f0391b28191037e598aebd4bcbb7');    
    }}

 

 

 

And this is the on change script that also doesn't work.(not auto populate the ownership group field)

Script (on change)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    if(oldValue != newValue){
        
    if (newValue == 'zh' && (g_form.getValue ('kb_knowledge_base')== 'dfc19531bf2021003f07e2c1ac0739ab')){
    g_form.setValue('ownership_group','6208f0391b28191037e598aebd4bcbb7');    
    }}

6 REPLIES 6

Thank you. What I found is. If I use the on load client script like this., it will be workable (auto populate the field)

 

function onLoad() {
   //Type appropriate comment here, and begin script below
  
    if (g_form.getValue('language') == 'zh' && g_form.getValue('kb_knowledge_base') == 'dfc19531bf2021003f07e2c1ac0739ab'){
    g_form.setValue('ownership_group','6208f0391b28191037e598aebd4bcbb7'); 
    
    }}

 

But If I add g_form.isNewRecord() in the condition, it's not workable. (not auto populate the field)

 

And also the 'on change' client script, it doesn't work. I found that when create a new KB article, the 'Knowledge base' field is empty, so we need to manually key in 'Knowledge' first and then the 'Language' field will be editable and allow us to choose the language. 

The client script could be based on only 1 field and I selected 'Language' field.

I am not sure that what should be the best solution to achieve it? I need if 'Knowledge base' = Knowledge && 'language' = 'zh' (Chinese) , the ownership field will auto populate.

 

 

find_real_file.png

@Bird 

Can you share your onChange client script code what you tried?