Set a drop down field as "yes" when a perticular record selected from a reference field

1_DipikaD
Kilo Sage

Hi All,

I have reference field category and a dropdown field field with yes and no on change table. I need to set the drop down value as "yes" when I select a particular record from category field . I have tried the below script but did not get expected result.

 

Actually I was trying on a different dropdown field that's why I take 8 in the script but actually I need yes as output as mentioned above.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var st = g_form.getValue("department");
   if (st === "5d7f17f03710200044e0bfc8bcbe5d43")
   {
    g_form.setValue("platform", '8');
   }

   //Type appropriate comment here, and begin script below
   
}
 
Thank you
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@1_DipikaD 

the below will work if you are comparing the correct sysId and the correct choice value

Also use == and not === to compare

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var st = g_form.getValue("department");
   if (st == "5d7f17f03710200044e0bfc8bcbe5d43") // give correct sysId
   {
    g_form.setValue("platform", '8'); // give correct field name and choice value
   }

   //Type appropriate comment here, and begin script below
   
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

View solution in original post

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var st = g_form.getValue("department");
   if (st == "5d7f17f03710200044e0bfc8bcbe5d43")
   {
    g_form.setValue("platform", 'sap');
   }

   //Type appropriate comment here, and begin script below
   
}
I tried this it is working but the drop down value is not changing with change with the reference field value .

View solution in original post

8 REPLIES 8

Vaibhav_Nikam
Tera Guru

Hi @1_DipikaD ,

Can you please try below code?


function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue == '') {         // change '===' to '==' 
      return;
   }
   if ( g_form.getValue("department") == "5d7f17f03710200044e0bfc8bcbe5d43") // change '===' to '==' 
   {
    g_form.setValue("platform", '8');                                        //set the values
   }

   //Type appropriate comment here, and begin script below
   
}

I correct the script it's working fine.

But drop down value is not changing while I am  changing the reference field value , it remains the same

Can you please check and share the backend name of dropdown field and the value you are setting? 

1_DipikaD
Kilo Sage

I am writting ui policy to clear the field vaue. Is it best practice ?