Username form requested_for, how to get it into my singleline text variable

FotinaG
Tera Contributor

Hello Guys,

 

I am afraid I got lost in getReference. I need to set automatically filled field in RITM/Sctask with user ID (from user record requested_for person). I created client script on Change. But still this field is empty. My autofilling thing didnt work. Could you please show me where is my mistake?

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    g_form.getReference('requested_for', setValue);
   
    function setValue(userId){
    g_form.setValue('username', userId.user_id_myfield);
    }
}

Thank you so much in advance 🙂

1 ACCEPTED SOLUTION

Arun_Manoj
Mega Sage

Hi @FotinaG ,

 

Please try below mentioned code

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.getReference('requested_for', function(userObj) {
if (userObj) {
g_form.setValue('username', userObj.user_name); // Adjust this field name
}
});
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,

Arun Manoj

View solution in original post

2 REPLIES 2

Arun_Manoj
Mega Sage

Hi @FotinaG ,

 

Please try below mentioned code

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.getReference('requested_for', function(userObj) {
if (userObj) {
g_form.setValue('username', userObj.user_name); // Adjust this field name
}
});
}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,

Arun Manoj

FotinaG
Tera Contributor

Thank you so much! Sorry for late reply!