Is it necessary to pass current object while calling script include from UI action condition?

Nick17
Giga Contributor

I am calling script include from UI action what will happen if i doesn't pass current object?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nick,

it's not necessary to pass the current object since it is the same calling scope.

But it is recommended to pass the current object from the UI action to the script include function considering how objects are treated in javascript.

Refer below link for more explanation

https://snprotips.com/blog/2019/12/18/can-script-includes-use-the-current-variable

Just tested for Form button and it worked well without sending the current object in script include function and was able to print the incident number

Screenshots below

UI Action:

find_real_file.png

Script Include:

find_real_file.png

Output: Printing the current inc number

find_real_file.png

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Nick,

You need to pass current object if you need to access the field values in the script include. Sample script below on how to pass current object.

For ex : var val = new HelloWorld();

val.test(current);

 

Now at script include end

test: function(gr)

{

var shortDesc = gr.short_description; 

}

 

- Pradeep Sharma

Understood

Thanks Pradeep 

Pratiksha Kalam
Kilo Sage

Hello,

You can add current object in Ui actions.

Script include Name:Hello

 

Script:

function Hello(){

gs.addInfoMessage(current.number);
 

}

 

I can then call that script include from an incident onBefore insert/update Business Rule with the script:

 

 function onBefore(current, previous) {

 

    sayHello();

 

}

If answer is helpful please mark correct!

Thanks,
Pratiksha

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nick,

it's not necessary to pass the current object since it is the same calling scope.

But it is recommended to pass the current object from the UI action to the script include function considering how objects are treated in javascript.

Refer below link for more explanation

https://snprotips.com/blog/2019/12/18/can-script-includes-use-the-current-variable

Just tested for Form button and it worked well without sending the current object in script include function and was able to print the incident number

Screenshots below

UI Action:

find_real_file.png

Script Include:

find_real_file.png

Output: Printing the current inc number

find_real_file.png

Regards
Ankur

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