Script Include is returning null, when being called from onLoad script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:34 AM
Hi All,
Thanks in Advance.
I am facing problem while retrieving the response from script include in onload script include, even though I am able to get the value in return value in script include but still while getting response in client script it is retrieving null.
Here is the script include and client script.
var DisplayModelName = Class.create();
DisplayModelName.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getName: function() {
var task_ID = this.getParameter('sysparm_task_ID');
var table_ID = this.getParameter('sysparm_table');
var gr = new GlideRecordSecure(table_ID);
gr.addQuery('sys_id', task_ID);
gr.query();
if (gr.next()) {
var instruct = gr.x_care3_carear_fsm_instruct_experience_value.getDisplayValue().toString();
gs.info("name of model" +instruct);
}
return instruct;
},
type: 'DisplayModelName'
});
CS:
function onLoad() {
//Type appropriate comment here, and begin script below
var doc;
var iframe = top.document.getElementById('gsft_main'); //main iframe
var listIframe = iframe ? iframe.contentWindow.document.querySelector('[name=gsft_list_form_pane]') : null; //split view iframe
//listIframe is null if iframe is null (when open record outside of frame, ie. not within nav_to) OR can not be determined by the selector above (for when the record is opened in regular form view, no split view)
if (listIframe == null) {
doc = iframe ? iframe.contentWindow.document : top.document;
} else
doc = listIframe.contentWindow.document; //listIframe exists when record is opened in split view, set doc to listIframe.contentWindow.document
var ur = new GlideAjax('x_care3_carear_fsm.DisplayModelName');
ur.addParam('sysparm_name','getName');
ur.addParam('sysparm_task_ID',g_form.getUniqueValue());
ur.addParam('sysparm_table', g_form.getTableName());
ur.getXML(labelURLCallback);
function labelURLCallback(response){
alert(response);
var answer = response.responseXML.documentElement.getAttribute("answer");
var modelname = answer;
//var modelURL = response;
alert(modelname);
}
var element = doc.getElementById('wm_task.x_care3_carear_fsm_instruct_experience_value.instruct_model_url_link');
//alert(g_form.getValue('x_care3_carear_fsm_instruct_experience_value'));
if (element)
//element.innerHTML = g_form.getValue('x_care3_carear_fsm_instruct_experience_value'); //set text of URL
//document.getElementById('x_snc_test_work_ap_test_table.model_url_link').innerHTML = "click me";
element.innerHTML = modelname;
}
Note: We are working on scoped application & we are trying update the field display value using inner HTML.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:56 AM
Hi Sushma,
Have you tried making the Isolate Script (A column/field on client scripts) value of client script to false?
Hopefully this will do the trick for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 07:07 AM
hello
i think your declared your variable which is returning from script include inside the loop which is not accessible in global way so try to declare it outside like below
var DisplayModelName = Class.create();
DisplayModelName.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getName: function() {
var instruct = '';
var task_ID = this.getParameter('sysparm_task_ID');
var table_ID = this.getParameter('sysparm_table');
var gr = new GlideRecordSecure(table_ID);
gr.addQuery('sys_id', task_ID);
gr.query();
if (gr.next()) {
instruct = gr.x_care3_carear_fsm_instruct_experience_value.getDisplayValue().toString();
gs.info("name of model" +instruct);
}
return instruct.toString();
},
type: 'DisplayModelName'
});
PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 07:58 AM
hello
did my script help ?if yes please close the thread by marking the answer correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 07:11 AM
Hi Sushma,
I can see one mistake in your script include script.
You have declared instruct variable inside if condition whose value outside if will be empty, please define instruct variables outside if condition, something like below.
var instruct ="";
if (gr.next()) {
instruct = gr.x_care3_carear_fsm_instruct_experience_value.getDisplayValue().toString();
gs.info("name of model" +instruct);
}
return instruct;
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP