To call one of the script include function in another function of the same script include

Dinesh90
Tera Contributor

Hello Everyone,

This is regarding one of my requirement 🙂

 

I want to use one of the variable value which is in one of the function in script include.

 

I want to use this variable value in another function which is in the same script include.

 

How to call one function to another function in the same script include and how to use the variable value of one function to another function in same script include.

Also , the variable value is getting returned to the glide ajax call in the function and I want to use the same variable value in another function in same script include.

 

Script include is the Client callable one.

 

Please help with the logic and code.

1 ACCEPTED SOLUTION

@Dinesh90 

unless Test function returns this you cannot access it

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Dinesh90 

you can call function of same script include within another function using this syntax and also you can pass the value to that function which is getting called

this.myFunction(variable);

It will be nice if you share the existing scripts and what you tried and what's not working as per expectations

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank @Ankur Bawiskar for the reply..

so as per the syntax you have mentioned - this.myFunction(variable);

I am taking one example here -

First function 

 

TEST : function (){

var abc = ' ' ;

doing some logic

 

return abc ;   /// returning the abc variable in this function

}

 

Second function :

Demo : function (){

// need to use the  abc variable in this function 

this.TEST(abc); 

}

 

can we do like this, I need to use the value of abc variable (which is in TEST function) in DEMO function.

should I store - this.TEST(abc) to any variable like below ?

var xyz = this.TEST(abc);

 

Do I need to pass the abc value as a parameter in DEMO function as well while declaration like below ?

Demo : function (abc){

}

@Dinesh90 

it would be like this

var xyz = this.TEST();

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

so @Ankur Bawiskar  , 

var xyz = this.TEST();   // adding this line in my DEMO function , will do the job ?

as I need to use the variable value "abc"  in DEMO function which is stored in TEST function.

Thanks !