Getting sys_id in server script directly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:27 AM
Hi Everyone,
Can I use current.sys_id in Script include directly to get sys_id of record. I don't want to send sys_id from Client Side (UI Action) but, want to directly get it on Script include.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:37 AM - edited 01-12-2024 04:56 AM
Hello @Virendra Dwived ,
No! we can't use current.sys_id to get sys_id of the record in script Include. Instead you need to pass sys_id from UI action only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:37 AM
basically yes, but the better approach is:
current.getValue('sys_id')
as current.sys_id would result in an additional database query.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:45 AM
Hi @Virendra Dwived,
Whilst you can use the syntax and current object to obtain the sys_id, please remember what a Script Include is and why it is used. Very high level, a Script Include is used to perform a lookup on the server that we want abstract from the Client layer. Therefore, when calling the Script Include you, of course, need to pass something from the Client in order to perform the lookup on the Server server side - eg a record number (or some unique data point).
It is here on the Server side and Script Include you can perform a query to obtain the sys_id.
Check the below link and article where theres a good example to obtain the sys_id
To help others, please mark this as correct and helpful,
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 02:47 AM
how and from where the script include is getting called?
Please give some background to your question
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader