- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 06:14 AM
Hello,
I have a form which has the two following fields:
requested_for: reference field to sys_user table (this is a variable set)
company: selectbox field, it has (value=) barco_tw question choice.
The requirement is that, if the location of the requested for is Taiwan, the company selectbox must be set to barco_tw value.
I have written the following simple client script to solve this issue but it does not work.
function onLoad() {
Get the value of the location using dot walking
var location = g_form.getValue('requested_for.location');
// Check if the location is Taiwan
if (location === '39089e421bdc2510f8104002cd4bcb3d') {
// Set the value of the "company" field to "barco_tw"
g_form.setValue('company', 'barco_tw');
}
// Attach the onLoad function to the onLoad event
if (window.g_form) {
g_form.addOnLoad(onLoad);
}
I also tried instead of sys_id, string 'TAI', it doesn't work either.
Any idea why this is not working? Is it the dot walking?
Thanks.
Best,
Firat
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:04 AM
@mfhaciahmetoglu , I tried the below solution on reference type variable for user field. And it is working correctly.
onChange Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckUserLocation');
ga.addParam('sysparm_name', 'getLocation');
ga.addParam('sysparm_user_sys_id', g_form.getValue('user'));
ga.getXMLAnswer(ans);
function ans(response) {
if (response == '25b3d04b0a0a0bb300176b546c22db27') {
g_form.setValue('company', 'barco_tw');
}
}
}
Script Include:
var CheckUserLocation = Class.create();
CheckUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation: function() {
var userSysId = this.getParameter('sysparm_user_sys_id');
var userGr = new GlideRecord('sys_user');
if (userGr.get(userSysId)) {
gs.info('userGr.location is '+ userGr.location)
return userGr.location;
}
},
type: 'CheckUserLocation'
});
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 07:42 AM
Are you getting the value for requested for in the client script ? try checking with logging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:04 AM - edited 01-02-2024 08:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 08:04 AM
@mfhaciahmetoglu , I tried the below solution on reference type variable for user field. And it is working correctly.
onChange Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CheckUserLocation');
ga.addParam('sysparm_name', 'getLocation');
ga.addParam('sysparm_user_sys_id', g_form.getValue('user'));
ga.getXMLAnswer(ans);
function ans(response) {
if (response == '25b3d04b0a0a0bb300176b546c22db27') {
g_form.setValue('company', 'barco_tw');
}
}
}
Script Include:
var CheckUserLocation = Class.create();
CheckUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation: function() {
var userSysId = this.getParameter('sysparm_user_sys_id');
var userGr = new GlideRecord('sys_user');
if (userGr.get(userSysId)) {
gs.info('userGr.location is '+ userGr.location)
return userGr.location;
}
},
type: 'CheckUserLocation'
});
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 01:13 AM
Hello @mfhaciahmetoglu ,
Did you tried this solution, it should resolve your problem. Maybe the variable set is the issue, I will suggest make a reference type variable and try this way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 01:19 AM
Hi Siddhesh,
I tried with a reference field named "user" but still no response at all. I am not sure if it is triggered. How I can log this?