- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 07:09 AM
Have populating the username and Uid when user load the form, I need to clear the value when change the user name and auto populate the Uid value with respect to given user name.
Have existing code onchange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(g_form.getValue("user") != ''){
var gr = g_form.getReference("user", callBack);
function callBack(gr) {
g_form.setValue('uid', gr.user_name);
g_form.setReadOnly('uid',true);
}
}
else
{
g_form.clearValue("uid",true);
}
}
with this script can populate values but when remove the user name and give another user name 'uid' is not clearing and not populating in 'uid' field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 07:13 AM
Hi @Mad3
Try this and let me know if it works:
function onChange(control, oldValue, newValue, isLoading) {
if(g_form.getValue("user")=="")
{
g_form.clearValue("uid");
}
var gr = g_form.getReference("user", callBack);
function callBack(gr) {
g_form.setValue('uid', gr.user_name);
g_form.setReadOnly('uid',true);
}
}
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:13 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (g_form.getValue("user") != '') {
var userField = g_form.getReference('user', callback);
} else {
g_form.clearValue("uid", true);
}
function callback(userField) {
g_form.setValue('uid', userField.user_name);
g_form.setReadOnly('uid', true);
}
}
Try this. I updated line 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:59 AM
Hi @Mad3 ,
I assume this is a onChange client script on a table that references the sys_user information (let's call it user) and you have a field called uid in that table.
Then what you are saying is when a person selects the information on the user field (onChange client script on the user field) the script is executed. What you must leverage on this onChange client script is the newValue variable, which is exactly what the person selected on the user field. So rather than typing "g_form.getValue("user")", you should just use newValue.
I think the top of the script is also playing against you since if the newValue is empty it will exit the code (return;).
You may want to remove that OR statement if your intention is to clear the uid field if the user clear the user field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) { return; }
if(!newValue){ //if there is NO value on user field
g_form.clearValue("uid"); //no need to add true at the end
} else {
var gr = g_form.getReference("user", callBack);
function callBack(gr) {
g_form.setValue('uid', gr.user_name); //have in mind that the "user ID" field on the sys_user table is called user_name
g_form.setReadOnly('uid',true);
}
}
}
If I helped you with your case, please click the Thumb Icon and mark as Correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 07:21 AM
Try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_form.getValue("user") != '') {
var userField = g_form.getReference('user', callback);
} else {
g_form.clearValue("uid", true);
}
function callback(userField) {
g_form.setValue('uid', userField.user_name);
g_form.setReadOnly('uid', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:01 AM - edited 11-07-2022 08:04 AM
Hi Mike,
Thank you for your reply.
For user variable we have used script in default. javascript: gs.getUserName();
and used onChange client script which you provided.
But I got one issue that is like
when I remove the user value still the user id is populating until user changes.
Can you please help me on this.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:13 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (g_form.getValue("user") != '') {
var userField = g_form.getReference('user', callback);
} else {
g_form.clearValue("uid", true);
}
function callback(userField) {
g_form.setValue('uid', userField.user_name);
g_form.setReadOnly('uid', true);
}
}
Try this. I updated line 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:59 AM
Hi @Mad3 ,
I assume this is a onChange client script on a table that references the sys_user information (let's call it user) and you have a field called uid in that table.
Then what you are saying is when a person selects the information on the user field (onChange client script on the user field) the script is executed. What you must leverage on this onChange client script is the newValue variable, which is exactly what the person selected on the user field. So rather than typing "g_form.getValue("user")", you should just use newValue.
I think the top of the script is also playing against you since if the newValue is empty it will exit the code (return;).
You may want to remove that OR statement if your intention is to clear the uid field if the user clear the user field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) { return; }
if(!newValue){ //if there is NO value on user field
g_form.clearValue("uid"); //no need to add true at the end
} else {
var gr = g_form.getReference("user", callBack);
function callBack(gr) {
g_form.setValue('uid', gr.user_name); //have in mind that the "user ID" field on the sys_user table is called user_name
g_form.setReadOnly('uid',true);
}
}
}
If I helped you with your case, please click the Thumb Icon and mark as Correct.