- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2015 11:57 AM
Hi all,
A quick one (hopefully 😞
I have a change request form which has a "classification type" field. If the classification type is set to "standard" then a new field appears, in which the user can choose the relevant standard change request. Standard changes are on a different table (u_standard_change_requests).
I would like to make it so that if a standard change is chosen, and a standard change number is inserted in the relevant field, two other fields in the change request form are populated with the information from the standard change. The two fields are short description and description.
I created a script include:
Name: getStandardFields
var getStandardFields = Class.create();
getStandardFields.prototype = {
getFields : function() {
var standardFields = new GlideRecord('u_standard_changes');
standardFields.addQuery('u_number', current.u_standard_change_num);
standardFields.query();
},
type: 'getStandardFields'
};
I created a client script:
On change of the field "Standard Change num":
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var classificationType = g_form.getValue('u_change_classification');
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.getXMLWait();
var findFields = ga.getAnswer();
if (classificationType == 'Standard') {
g_form.setValue('short_description', findFields.u_name_of_the_change); //This line is probably incorrect?
}
}
u_name_of_the_change is the name of the field in the standard change, that I want to copy to short_description in the current change request form.
So my question is: how do I get to populate the change request "short_description" with values from the standard change?
Thoughts?
Harel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2015 02:46 PM
Hi Harel,
I have modified your script include and client script. See below.
Script Include: (Ensure the client callable checkbox is checked)
var getStandardFields = Class.create();
getStandardFields.prototype = {
getFields : function() {
var stdChange = this.getParameter('sysparm_std_change');
var standardFields = new GlideRecord('u_standard_changes');
standardFields.addQuery('sys_id', stdChange);
standardFields.query();
if(standardFields.next()) {
return standardFields.u_short_description + '|' + standardFields.u_description;
}
return '';
},
type: 'getStandardFields'
};
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var classificationType = g_form.getValue('u_change_classification');
if (classificationType == 'Standard') { //MAke server call only if the type is Standard
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam("sysparm_name", "getFields"); //this is the function within the script include
ga.addParam("sysparm_std_change", g_form.getValue('u_standard_change_num'));
ga.getXML(getResponse);
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
g_form.setValue('short_description', values[0]);
g_form.setValue('description', values[1]);
}
}
Please let me know if any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2015 12:07 PM
Also instead of returning empty string after IF, try to put
return "No Record";
This is just to make sure that flow is not going into IF statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2015 12:46 PM
Done that. Still null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2015 12:59 PM
If it is populating null always means, connection between client script and script include has problem (hope so)...
first try to work with returning single value
if you dont mind, can you post your recent scripts again with returning single value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2015 01:15 PM
OK, so... sort of found the problem:
This:
getStandardFields.prototype = Object.extendsObject(AbstractAjaxProcessor),{
should have been this:
getStandardFields.prototype = Object.extendsObject(AbstractAjaxProcessor,{
Yes, I feel a bit stupid now
The two scripts, in case anyone needs anything like it:
client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var classificationType = g_form.getValue('u_change_classification');
if (classificationType == 'Standard') { //MAke server call only if the type is Standard
var standardChangeNum = g_form.getValue('u_standard_change_num');
var ga = new GlideAjax('getStandardFields');//this is the script include
ga.addParam('sysparm_name', 'getFields'); //this is the function within the script include
ga.addParam('sysparm_std_change', standardChangeNum);
ga.getXML(getResponse);
}
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer').toString().split('|');
g_form.setValue('short_description', values[0]);
g_form.setValue('description', values[1]);
}
}
and script include:
var getStandardFields = Class.create();
getStandardFields.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getFields : function() {
var stdChange = this.getParameter('sysparm_std_change');
var standardFields = new GlideRecord('u_standard_changes');
standardFields.addQuery('sys_id', stdChange);
standardFields.query();
if(standardFields.next()) {
return standardFields.u_name_of_the_change + '|' + standardFields.u_description;
}
return 'No Record';
},
type: 'getStandardFields'
});
Thank you, Guhan, for fixing the scripts and thank you both for the help with troubleshooting.
Much appreciated!
Harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2015 01:46 PM
Finally