- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2015 06:46 AM
Hi All,
I have written a client callable script include to set some reference field values on SRM form.
But whenever script include returns 'undefined' value the reference field values are setting with some value and the color of the field is changed to green even though the filed is empty. Please see the below screen shot
Please let me know if you have any idea on this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2015 10:13 PM
I fixed this issue by modifying the client side script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue != '')
{
locationValues(newValue);
}
else{
if(g_form.getValue('location1') != "")
g_form.setValue('location1',"");
if(g_form.getValue('location2') != "")
g_form.setValue('location2',"");
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
}
}
function locationValues(newValue){
var ajax = new GlideAjax('SiteContactChange2');
ajax.addParam('sysparm_name','getSiiteContact2');
ajax.addParam('sysparm_id2',newValue);
ajax.getXML(getResult);
}
function getResult(serverResponse){
var result = serverResponse.responseXML.getElementsByTagName("result");
var locat1 = result[0].getAttribute("loc1");
g_form.setValue('location1',locat1);
var locat2 = result[0].getAttribute("loc2");
if(locat2 != "undefined"){
g_form.setValue('location2',locat2);
}
else
{
if(g_form.getValue('location2') != "")
g_form.setValue('location2',"");
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
var locat3 = result[0].getAttribute("loc3");
if(locat3!= "undefined"){
g_form.setValue('location3',locat3);
}
else
{
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
var locat4 = result[0].getAttribute("loc4");
if(locat4!= "undefined"){
g_form.setValue('location4',locat4);
}
else
{
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2015 08:01 AM
Hi,
What happens if you return an empty string? Do you get the same behavior?
return typeof your_variable === "undefined" ? "" : your_variable;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 12:04 AM
In this way I tried by using return but still it is not working
It is working for first change of field name but when I changed the user name second time the filed colors are changed to green even though the the value is empty
var result = serverResponse.responseXML.getElementsByTagName("result"); | |||
var locat1 = result[0].getAttribute("loc1");
g_form.setValue('location1',locat1);
var locat2 = result[0].getAttribute("loc2");
if(locat2 != "undefined"){ |
alert('not undefine2'); | ||
g_form.setValue('location2',locat2); | ||
} | ||
else | ||
{ | ||
alert('undefine2'); | ||
g_form.setValue('location2',""); | ||
g_form.setValue('location3',""); | ||
g_form.setValue('location4',""); |
return typeof locat2 === "undefined" ? "" : locat2; | ||
} |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 09:38 AM
Sorry, I meant to use the return statement on the script include to return an empty string instead of undefined.
Can you post the entire code that you are using for this? Script include and full client script?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2015 10:13 PM
I fixed this issue by modifying the client side script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue != '')
{
locationValues(newValue);
}
else{
if(g_form.getValue('location1') != "")
g_form.setValue('location1',"");
if(g_form.getValue('location2') != "")
g_form.setValue('location2',"");
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
}
}
function locationValues(newValue){
var ajax = new GlideAjax('SiteContactChange2');
ajax.addParam('sysparm_name','getSiiteContact2');
ajax.addParam('sysparm_id2',newValue);
ajax.getXML(getResult);
}
function getResult(serverResponse){
var result = serverResponse.responseXML.getElementsByTagName("result");
var locat1 = result[0].getAttribute("loc1");
g_form.setValue('location1',locat1);
var locat2 = result[0].getAttribute("loc2");
if(locat2 != "undefined"){
g_form.setValue('location2',locat2);
}
else
{
if(g_form.getValue('location2') != "")
g_form.setValue('location2',"");
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
var locat3 = result[0].getAttribute("loc3");
if(locat3!= "undefined"){
g_form.setValue('location3',locat3);
}
else
{
if(g_form.getValue('location3') != "")
g_form.setValue('location3',"");
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
var locat4 = result[0].getAttribute("loc4");
if(locat4!= "undefined"){
g_form.setValue('location4',locat4);
}
else
{
if(g_form.getValue('location4') != "")
g_form.setValue('location4',"");
return;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2015 11:09 AM
Hi Md,
Have you looked at the glideajax wiki? The link below shows a pretty good example on how to return more than one value from a script include via ajax.