To get UserID in Onchange() Client Script

Ashok32
Tera Contributor

Hi All,

 

   I have a "request for" reference field in that field default value is logged in userid. So, If I select "exists"(its a checkbox) as No, then request for should be cleared. When I select back to "exists" as 'Yes' then UserID should be populated. 

 

 

Can anyone help me to achieve this.

 

Thanks in advance

5 REPLIES 5

Vamshi Krishna2
Tera Contributor

Hi,

Write a ui policy if exists is true as below. use exists in place of active

VamshiKrishna2_0-1675098923196.png

click advanced and write a condition 

VamshiKrishna2_1-1675098998839.png

 

 

Prince Arora
Tera Sage
Tera Sage

@Ashok32 ,

 

Please try below mentioned code:

Client Script : on change
variable: on check Box(exist)

script:


if(newValue+"" == "true"){

g_form.setValue('requested_for',g_user.userID);

}else{

g_form.clearValue('requested_for');

}

 

Please mark my answer helpful, if it works for you.

Vamshi Krishna2
Tera Contributor

Hi Not sure about check box but you make attachments mandatory by using the checkbox in catalog item as below

VamshiKrishna2_0-1675099481014.png

 

Anurag Tripathi
Mega Patron
Mega Patron

Try this

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ref = g_form.getValue('<ecists field>'); // use correct field anme
   
if(ref == 'Yes') //make sure you use correct value
        g_form.setValue('<requested_for>', g_user.userID); // use correct field anme
   else
         g_form.clearValue('<requested_for>'); // use correct field anme
}

 

-Anurag