- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 08:39 AM
Hello All,
I have a use case, where I have to check for condition if parent field is empty or not.
1) If parent field is not empty then I have to call my script include.
2) If parent field is empty, then do nothing.
I have to check these things as soon as form load, so I'm using onload client script, but it is not checking the empty for parent field empty everytime it goes for another condition. Can anyone help hea?
Note: Everytime it is going in else section.
function onLoad() {
var parentField = g_form.getValue('parent');
alert(parentField);
if( g_form.getValue('parent')== undefined){
alert("Empty");
}else{
alert("Glideajax");
var ga = new GlideAjax('x_kpm14_security_i.PopulateTaskType'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('parentID',parentField); //Parameters
ga.getXMLAnswer(getResponse);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 08:41 AM
Can you try
function onLoad() {
var parentField = g_form.getValue('parent');
alert(parentField);
if( g_form.getValue('parent') == ""){
alert("Empty");
}else{
alert("Glideajax");
var ga = new GlideAjax('x_kpm14_security_i.PopulateTaskType'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('parentID',parentField); //Parameters
ga.getXMLAnswer(getResponse);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 08:41 AM
Can you try
function onLoad() {
var parentField = g_form.getValue('parent');
alert(parentField);
if( g_form.getValue('parent') == ""){
alert("Empty");
}else{
alert("Glideajax");
var ga = new GlideAjax('x_kpm14_security_i.PopulateTaskType'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('parentID',parentField); //Parameters
ga.getXMLAnswer(getResponse);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 08:59 AM
sorry for misunderstanding.
I copy pasted wrong one. Correct if condition below:
var parentField = g_form.getValue('parent');
if( parentField== ''){
alert("Empty");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 09:37 AM
Got it. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 08:42 AM
Hi,
Can you please try
if( g_form.getValue('parent')== ''){
in place of undefined
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***