Unable to show error message

Mahesho11
Tera Contributor

 have shared u the screenshot please check. 

Here the problem is in security group table - I have filled security group name with the help sys_user_group, and owner from sys_user table. I have given some value to both. for example after the form is submitted I have deleted the user in that form. In catalog item if i selected the security name the owner should auto populate. So, if I use same security name then the owner is showing empty but I unable to show error message the form is submitting automatically. So, I got to know later the sys_id is present but the user got deleted with the help of alert and getValue i found it. 

 

This scenario is I am facing in my DEV environment in my project. Can u please guide me how to remove that sy_id if value is empty. 

Please help me and explain in detail.

 

 

 

In a table records the user is deleted 

ex- security table 

 

application name - reference - sys_group

owner - reference - sys_user -mandatory-  here after record is submitted.

the user is deleted in table for some of application name. So, in that place empty field owner sys-id is coming so I unable to show error message on submit client script if owner is empty because of sys id the form is submitting. 

Screenshot 2024-01-21 004923.pngScreenshot 2024-01-21 005053.pngScreenshot 2024-01-21 005404.png

2 ACCEPTED SOLUTIONS

Aniket Chavan
Tera Sage
Tera Sage

Hello @Mahesho11 ,

Please give a try to the script below and see how it works for you.

function onSubmit() {
    // Type appropriate comment here, and begin script below
    var owner_a = g_form.getDisplayValue('owner_name');
    
    // Check if owner_a is empty or undefined
    if (!owner_a) {
        g_form.addErrorMessage('Owner field cannot be empty');
        return false; // Prevent form submission
    }

    // Additional check to ensure sys_id is not empty
    var owner_sys_id = g_form.getValue('owner');
    if (!owner_sys_id) {
        g_form.addErrorMessage('Owner sys_id is empty. Please select a valid owner.');
        return false; // Prevent form submission
    }

    // Continue with form submission if all checks pass
    return true;
}

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

 

View solution in original post

I would try this:

- make sure the Catalog Client Script is not active.

- modify the Auto-populate configuration so that field Dot walk path points not to Owner, but Owner.Sys ID.

 

In such a configuration the system should not be able to fill in any value because ti will not be possible to get the Sys ID of an Owner that that does not actually exist.

In such a configuration your original script should work (and should display nothing when alert-ing the contents of field Owner name)

View solution in original post

11 REPLIES 11

Narsing1
Mega Sage

You can modify like this

if (g_form.getValue("owner_name") == "") {
	g_form.addErrorMessage("field can't be empty");
	return false;
}

Thanks,

Narsing

I used this code. But my problem is with the user is not present but sys_id is coming in that area. I got know with the help of 

 

var owner = g_form.getValue('owner_name');

alert(owner);

Aniket Chavan
Tera Sage
Tera Sage

Hello @Mahesho11 ,

I appreciate your explanation, and it seems like you've identified the sys_id of the deleted user through the alert. However, there's still some confusion in understanding the overall issue. Could you please provide more context or insights into the specific challenge you're facing?

Additionally, to expedite the resolution, it would be helpful if you clarify whether your focus is on fixing the "Owner" variable or the "Owner Name." This distinction will assist in tailoring the solution to the correct aspect of your form.

Please let me know your views on this.

-O-
Kilo Patron
Kilo Patron

You say

In catalog item if i selected the security name the owner should auto populate.

How did you configure that?

Did you configure Auto-populate for Owner name, or perhaps created some Catalog Client Script?

 

By the way it is confusing to name references as Something name.

Just because the field is showing the name of Something, it is in fact a reference to Something sot it should be named Something.

Thus the not-confusing correct name for Owner name is Owner and for Security group name is Security group.

Only if Owner name would not be a reference but a single line text and it would contain the name of the owner, then it would be correct to name the field as such.

Mahesho11
Tera Contributor

Mahesho11_1-1705883451159.png

Even I have used getReference method also 

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

  var user = g_form.getReference("security_group", populateManager);//confirm your field name
}

function populateManager(user) {
  g_form.setValue("owner_name", user.owner_name);//confirm your field name and referenced table field name
}  

 Later I also seen in the table of security group that i run a filter condition 

owner_name is empty then it is not showing any value there. and in user table with the empty field sys_id I searched in user table there I cant seen any user there. and in security table the form is mandatory for owner and in form is empty.