How to call a script include in the Relationship table?

thrsdy1512
Tera Expert

I have created a Script Include and want to call it in the below query, what is the best way to code this? I am creating a new relationship to display in a related list, similar to this: How to create Scripted Relationships or Defined Re... - ServiceNow Community

 

Thanks

thrsdy1512_0-1739956468075.png

 

 

11 REPLIES 11

maheshkhatal
Mega Sage

@thrsdy1512 You just need to call the Script include as

new yourScriptIncludeName().some1Function();// function which is just doing something.

var result = new yourScriptIncludeName().some2Function(pass_some_value);//function that returns something
gs.info('The result is:'+result); 

Mark my response as helpful if it resolved your doubt.

Thank you,

Mahesh

do i ned to create a new function as part of this or should i use a function from my script include?

@thrsdy1512 

it's as per your wish. create a new function or use an existing one if no code change is required in that function.

Did you check my below response?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@thrsdy1512 

syntax will be similar to how you call from any server side

var returnValue = new ScriptIncludeName().functionName()

In your case if you wish to show approval records for your CHG then no script include required, this will work

current.addQuery('sysapproval', parent.sys_id);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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