- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 10:17 AM
Hello:
I have a record producer with two variables:
var_number: Reference to alm_hardware table.
var_state: String
When the user selects an alm_hardware record in the var_number field, I'd like 'state' from the same record to be displayed on the form, in the var_state field. I've tried setting the default value of the var_state variable, for example: g_form.setValue('var_number'), with no success. Thanks in advance for any help.
Christine
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 01:14 PM
Make sure to delete that client script you made on the Record Producer table. You want to create a Catalog Client Script on your record producer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 10:35 AM
Setting this involves - g_form.setValue('var_number', "value" or variable your trying to set)
First you need to define a variable that fetches the Reference to the alm_hardware record.
Then you need to dot walk to the state field of that reference and define that- then you need to put that value the way I showed - if you get a variable you dont need "" in G-form setValue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 10:37 AM
You would need to do either a GlideAjax call or a getReference on an onchange script;
Here is an example of getReference
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setValue('var_state', "");
return;
}
var hardware = g_form.getReference('var_number', setFields);
}
function setFields(hardware) {
g_form.setValue('var_state', hardware.state);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 11:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2021 12:40 PM
For your situation, use a GlideAjax call instead. A getReference will get the state value not the state Display Value.
Here is what you need to do
1)Create a Script Include
2)Create a Catalog OnChange Script - on the record producer you created
Script Include
var getHardware = Class.create();
getHardware.prototype = Object.extendsObject(AbstractAjaxProcessor, {
gethardwareState: function() {
var hardwareSyS = this.getParameter('sysparm_hardware');
var hardware = new GlideRecord('alm_hardware');
hardware.get(hardwareSyS);
return hardware.getDisplayValue('install_status');
},
type: 'getHardware'
});
On Change Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setValue("state", "");
return;
}
var ga = new GlideAjax('global.getHardware');
ga.addParam('sysparm_name', 'gethardwareState');
ga.addParam('sysparm_hardware', newValue);
ga.getXML(setFields);
}
function setFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("state", answer);
}
Example of the Record Producer and Variables