- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 06:44 AM
I have a requirement like their is two fields one is choice and another is reference. based on choice field selection the reference field values should change.
example: choice field have A,B,C . if A is selects the reference field should show only few options.
if B is selects the reference field should show only few other options.
i used advanced reference qualifier : new Reference_field_validate().getUsers(current.request_type);
script include like :
Any one can help me regarding this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 11:56 AM - edited 04-01-2024 12:00 PM
Hello @surendra Gelivi ,
There is a syntax error (current.variables.request_type you should pass a parameter) in your reference qualifier please correct it like below:
Syntax of advanced reference qualifier:- javascript: new Reference_field_validate().getUsers(current.variables.request_type);
I have created a similar case in my PDI it's working fine. Can you try applying the same. My case the filter condition is applying with title.
Note: Go and create a new script include and make sure check the client callable option.
You can try update your function code like below once.
getUsers: function(request_type) {
var Equery;
var users = [];
gs.info("ReqType:"+request_type); // To check the value is coming or not
if (request_type == 'A') {
Equery = 'u_levelINSr Director,Managing Director,Partner,Principal,Income Partner'; // Check the backend value for level.
}else{
Equery = '';
}
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(Equery);
gr.query();
while (gr.next()) {
users.push(gr.sys_id.toString());
}
gs.info("User List:"+users);
return 'sys_idIN' + users;
},
Below are the ref screenshots:
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 10:29 AM - edited 04-01-2024 12:21 PM
I would assume you are getting unexpected results. If the reference field shows all of the records from the sys_user table regardless of the choice, then it's having trouble calling the Script Include, or with the GlideRecord - ignoring the encoded query. Confirm that the reference field is on the sys_user table, and the choice field value (not the label) is exactly what you are using in your if statement. Temporarily add some gs.addInfoMessage lines like this to confirm what is happening in the script:
var Reference_field_validate = Class.create();
Reference_field_validate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUsers: function(request_type) {
var reqType = request_type;
gs.addInfoMessage('SI running. Request type = ' + reqType);
var Equery = "";
var gr = new GlideRecord('sys_user');
if (reqType == 'A') {
Equery = 'u_levelINSr Director,Managing Director,Partner,Principal,Income Partner';
}
gr.addEncodedQuery(Equery);
gr.query();
var users = [];
while (gr.next()) {
gs.addInfoMessage('User found ' + gr.name);
users.push(gr.getUniqueValue());
// users.push(gr.getValue('sys_id'));
}
// return users.join(',');
return "sys_idIN" + users.join(',');
},
type: 'Reference_field_validate'
});
You'll also want to manually filter a list view of users by the elements in your encoded query, then right-click on the breadcrumb and choose Copy Query to confirm that this is correct.
Your continued use of the word field, as opposed to variable, and no mention of a Catalog Item has lead me to believe that this is happening on a table form. If in fact you are using this on a Catalog Item variable, and we were somehow supposed to know this, then add .variables prior to request_type on your reference qualifier:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 11:56 AM - edited 04-01-2024 12:00 PM
Hello @surendra Gelivi ,
There is a syntax error (current.variables.request_type you should pass a parameter) in your reference qualifier please correct it like below:
Syntax of advanced reference qualifier:- javascript: new Reference_field_validate().getUsers(current.variables.request_type);
I have created a similar case in my PDI it's working fine. Can you try applying the same. My case the filter condition is applying with title.
Note: Go and create a new script include and make sure check the client callable option.
You can try update your function code like below once.
getUsers: function(request_type) {
var Equery;
var users = [];
gs.info("ReqType:"+request_type); // To check the value is coming or not
if (request_type == 'A') {
Equery = 'u_levelINSr Director,Managing Director,Partner,Principal,Income Partner'; // Check the backend value for level.
}else{
Equery = '';
}
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(Equery);
gr.query();
while (gr.next()) {
users.push(gr.sys_id.toString());
}
gs.info("User List:"+users);
return 'sys_idIN' + users;
},
Below are the ref screenshots:
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 11:51 PM
Hi @Appanna M
Thanks for your response it was working good but it was not validating "if" conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 11:10 AM
Hello @surendra Gelivi ,
It should work for sure. Can you print the value before checking once and see the back end choice value of the request type. Then try once.
Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.