- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 02:09 AM
Hi,
I've been trying to set the value of a field in incident form through a record producer(accessd from service portal). Now I am using a script include in an onsubmit client script to get this value.
function onSubmit() {
//Type appropriate comment here, and begin script below
var p = g_form.getValue('Asset_Tag');
var ga = new GlideAjax('Get_asset_tag'); //Name of the Script Include
ga.addParam('sysparm_name', 'asset_tag'); //Name of the function in the script include
ga.addParam('sysparm_sys_id', p); //Parameter to pass to the script include g_form.getValue('Asset_Tag')
ga.getXML(CheckAssetTag);
function CheckAssetTag(response) {
var y = response.responseXML.documentElement.getAttribute("answer");
alert(y);
// var r = y;
g_form.setValue("description",y);
}
}
The alert works fine here and gives perfect value however not sure why this is not setting the value. This is only happening when i am using script include. I think I am making a very little mistake but not able to find it out.Looking for help.
THanks
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 03:16 AM
the reason for your issue is: the form is submitted to server before your glideAjax return value.it wont be visible to you because it will happen in milliseconds it will look like it was ubmitted after receiving the response but technically it will be submitted before getting response from server. you need to make your aJax call to synchronus call to wait for response before submitting form or you can modify it to onchange client script to fix this.
suggestion:
is description refers a variable in your record producer? or field in incident?
if it refrs to a variable in record producer form- it is of no use because you are populating a value in form during submit. Instead replace your ajax call into server function script section of record producer.
set the result to incident directly using the below:
current.description = new Get_asset_tag().asset_tag(producer.Asset_Tag);
add the above code to your script section of your record producer.
need slight changes in your script include function to make this working, share your script include if need any assistance in doing that.
-satheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 04:35 AM
Understood,
description is the field on incident table, not on record producer. I've unchecked the client callable checkbox in sctipt include now the alert started returning null value.
Secondly, My requirement is quite different and cant use producer variable for this. Not sure about the synchronous call of script include. Please check . Here is the requirement:
The required functionality is to get the values from multiple fields(variables) of the form(record producer) and set their concatenation within one field(description). All the fields were either string or choices except this once(reference). When I tried the getvalue and setvalue it is working for all other fields but in this field(asset_tag) i am getting the sys_id of selected records. For this i've created a script include and retrieved the displayvalue thorugh gliderecord and when placed the scriptinclude within my client script it is retrieving the exact value within the "alert" however not setting the value of description. I am unsure if script include works on record producers or not
Here is the script include i used:
var Get_asset_tag = Class.create();
Get_asset_tag.prototype = Object.extendsObject(AbstractAjaxProcessor, {
asset_tag : function(){
var x= this.getParameter('sysparm_sys_id');
var ga = new GlideRecord("u_cmdb_ci_computer_euc");
ga.addQuery("sys_id",x);
ga.query();
if(ga.next()){
return ga.name;
}
},
type: 'Get_asset_tag'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 04:42 AM
try now.
Updated script:
Script Include : It should not be client callable.
var Get_asset_tag = Class.create();
Get_asset_tag.prototype = {
initialize: function() {
},
asset_tag : function(x){
var ga = new GlideRecord("u_cmdb_ci_computer_euc");
ga.addQuery("sys_id",x);
ga.query();
if(ga.next()){
return ga.name;
}
},
type: 'Get_asset_tag'
};
Record Producer Script:
current.description = new Get_asset_tag().asset_tag(producer.Asset_Tag);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 05:04 AM
Could you change the code of Script Include to use return String(ga.name); instead of return ga.name; (ga.name is object and not a string)? Additionally it would be helpful if you would post the exact names of fields of Record Producer and the type of data. I mean that I find a little suspected, that you use var p = g_form.getValue('Asset_Tag'); with capital 'A' in the name of variable 'Asset_Tag'. It's not typical naming conversion, but if you use capital name for one field, than it could be that the name of another field is 'Description' instead of 'description'?
Additionally you can add more alerts in your code to get and display the description before and after g_form.setValue("description",y);:
alert("new description=" + y);
g_form.getValue("description");
alert("befor setValue: " + g_form.getValue("description"));
g_form.setValue("description",y);
alert("after setValue: " + g_form.getValue("description"));
You can debug the client code in Developer Tools of Chrome to see exact values and the type of data.
I suppose that you have some small error, but you probably not posted enough information that other developers can help you.
By the way, you can use
var ga = new GlideRecord("u_cmdb_ci_computer_euc");
return ga.get(x) ? String(ga.name) : "";
instead of
var ga = new GlideRecord("u_cmdb_ci_computer_euc");
ga.addQuery("sys_id",x);
ga.query();
if (ga.next()) {
return ga.name;
}
in your server code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2019 05:40 AM
Hi,
getXML(call back method name) - is a asynchronous method of execution, it means from this point, the execution will get split into two thread and both will get execute parallel. In your case,
Thread 1 : Form Submission
Thread 2 : Fetching the data from Script Include and populate into description field.
Before the thread 2 completion, thread 1 would have submitted the form, hence you are not able to view the change.
To fix this issue, we have to use getXMLWait(), this is synchronous method of execution, this will executes with the single thread.
Please do refer for more detail.
Regards
Bala T