Setdisplayvalue not working with record producer

akshay707
Tera Contributor

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

1 ACCEPTED SOLUTION

SatheeshKumar
Kilo Sage

 

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

 

 

 

 

 

 

 

View solution in original post

13 REPLIES 13

then in that case you have to call the script include (it should not be client callable ) in the script field on record producer.

if you see the @satheesh response , he has already pointed you in right direction. kindly try with his solution. 

 

Reason : if you are setting the variable value using client script then that variable should be available on form. 

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Could you describe what you are functionally trying to achieve? Sounds like this could be done a lot easier and thru server side scripting instead of client side scripting. Though, not sure about your functional question.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hey mark,

 

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 and that's why looking for some help in the scenario.

 

Thanks

AbhishekGardade
Giga Sage

Hello Akshay,

Try using code as below:

g_form.setValue('description',y)

Thanks,

Abhishek

Thank you,
Abhishek Gardade

SatheeshKumar
Kilo Sage

 

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