The CreatorCon Call for Content is officially open! Get started here.

Need help in validating empty reference field

Tanya10
Tera Contributor

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);
    }    

1 ACCEPTED SOLUTION

Akif_Shah
Kilo Sage

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);
    }   

View solution in original post

6 REPLIES 6

Akif_Shah
Kilo Sage

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);
    }   

sorry for misunderstanding. 

I copy pasted wrong one. Correct if condition below:

 var parentField = g_form.getValue('parent');
    
    if( parentField== ''){
        
        alert("Empty");

}

Got it. Thanks

Yousaf
Giga Sage

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.***