Clear Value is not working on client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2018 06:06 AM
I have validated Single text variable if existing table record is there or not. If is there need to show up alert message and need to clear the value.
here alert is working fine , but clear value is not working.
*** once I added g_form.setValue('new_site_url',''); then keep on clearing the variable value , even the record is not there in table:
Alert popup is working ,With out 'g_form.setValue('new_site_url','')' is working fine .
Could you please help me on this.
Please fin the below client script and script include --------------
client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var folderd = new GlideAjax("site_url_sharepoint");
folderd.addParam("sysparm_name", "getFolderDetails");
folderd.addParam("sysparm_new_folder_name", g_form.getValue('new_site_url'));
folderd.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
//alert(answer);
if(answer == 'true')
alert('Existing Site URL is available, please enter the new Site URL name');
g_form.setValue('new_site_url','');
}
}
===============
Script Include:
var site_url_sharepoint = Class.create();
site_url_sharepoint.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFolderDetails: function(){
var newFolder = new GlideRecord('u_shared_folders');
newFolder.addQuery('u_folder', this.getParameter('sysparm_new_folder_name'));
newFolder.query();
if(newFolder.next())
return true;
},
type: 'site_url_sharepoint'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2018 06:31 AM
Am i correct in thinking when you script include returns true you want to say 'that name exists already, pick another one?' The script you have shared doesn't actually have clearValue() in it so i'm not sure where this isn't working for you.
i would change you script include slightly, try below:
var site_url_sharepoint = Class.create();
site_url_sharepoint.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFolderDetails: function(){
var answer = false;
var newFolder = new GlideRecord('u_shared_folders');
newFolder.addQuery('u_folder', this.getParameter('sysparm_new_folder_name'));
newFolder.query();
if(newFolder.next()){
answer = true;
}
},
type: 'site_url_sharepoint'
});
Then change you client script as below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var folderd = new GlideAjax("site_url_sharepoint");
folderd.addParam("sysparm_name", "getFolderDetails");
folderd.addParam("sysparm_new_folder_name", g_form.getValue('new_site_url'));
folderd.getXMLAnswer(ajaxResponse);
function ajaxResponse(response) {
if(response == true){
alert('Existing Site URL is unavailable, please enter the new Site URL name');
g_form.clearValue('new_site_url');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2018 06:44 AM
Thank you for the replay,
As you suggested I have updated the above changes, but not working.
I have created separate onchange client script for clearValue. Now is working fine.
Please explain me any one on this, how is working with two client scripts..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2018 07:18 AM
I have no idea! Are both triggering? Are they identical? Put different alerts in each and see which comes up. Feel free to post both scripts if you want.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2018 06:42 AM
even if you don't have URL in table your are getting alert as true?