- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 06:47 AM
Good morning,
I need help with a script.
Vendor records are created in ServiceNow on "core_company" and each night a process runs to sync with our accounting system. I've been asked to provide a link to the newly created record in a new field.
What kind of field would I need to add to be able to do this? URL or String?
The idea is that with this link, we will be able to access ServiceNow from the accounting system quickly.
Here's the script I need.
Table: core_company
When: Before
Insert = True
When record is inserted, add a link to the current record to the record link field.
Hope this makes sense and someone can get a quick "correct answer"
Thanks in advance for the time and help!!!
Carl
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 08:01 AM
Create a before insert business rule and put this code in there
current.<field name>= 'https://'+ gs.getProperty('instance_name') + '.service-now.com/' + current.getTableName() + '.do?sys_id=' + current.sys_id;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 06:56 AM
Hi Carl,
This doesn't sound too complex. Under the hood, a URL is a string, just rendered as a clickable link.
If you want to generate a link to the current record in your business rule, it would look something like this:
var url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/' + current.getTableName() + '/?sys_id=' + current.sys_id;
// Save 'url' where you feel appropriate
#untested code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 07:06 AM
thanks Chuck.
Not sure how to read this. Do I need to put the table name in the script or is this getting it for me? Do I need a function or do I delete that and just paste this code in?
As for "//save URL where you feel appropriate", u_vendorlink_url is the field I want to save it on but not sure how to script to do that.
Sorry, I always forget to mention I don't yet know how to read scripts aside from identifying the field and tables

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 07:25 AM
Hi Carl,
In order to answer that, I would need more details around this:
Vendor records are created in ServiceNow on "core_company" and each night a process runs to sync with our accounting system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2016 07:33 AM
sorry. hard time wording things this morning.
When a vendor record is created in servicenow, I need to have a link to that newly created record saved in u_vendorlink_url
During our nightly process, (REST API) the link in that field will be passed to a field on our accounting table so they can access the vendor directly by clicking on the link I provide.
How it works on the Accounting system side, I don't know, but if I pass them the URL to the vendor record, my work is done
On the form it looks something like the attached but of course I want it to be to my instance for the record I create. (I don't plan to leave this on the form as it's only useful from the external system.)