Sys_id of ticket where the action originated

w_bouwer
Mega Expert

Hi,

I'm looking for an easy way to find the sys_id of the record where the action originated from, from a before insert business rule.

I know this works:

var x = gs.action.getGlideURI().toString();


But that requires me to write a indexOf check to cut the 'sysparm_sys_id' out of there. Plus I am not 100% sure on how these glideURI's are created, and therefore not whether my indexOf will always yield the correct result.

If anyone can help me on this, I'd be much obliged.

Wesley
11 REPLIES 11

mdwallick
Giga Contributor

So...in a business rule you want to get the sys_id of...what? The record you came from? The current record that your business rule is running on?

If the latter, it's as simple as:



var x = current.sys_id;


A bit more detail might help.


w_bouwer
Mega Expert

Hi Mike,

I want the sys_id of the record where the action started. Assuming you make an update on an incident ticket, that creates an email. I'm writing my business rule on the sys_email table. How do I get my incident sys_id in the business rule on the sys_email table?

Using current here would cause the sys_id to be of the record on the sys_email table.

Wesley


mdwallick
Giga Contributor

Ah, that's easy enough too. The instance field on a sys_email record is the sys_id of the "document" the email is related to. Also, there is a target_table field which tells you what table to look in based on the instance's sys_id.

For example, in a business rule on the sys_email table:



var gr = new GlideRecord(current.target_table);
if (gr.get(current.instance)) {
// do something with the GlideRecord you get back
}


Does that get you what you need?


Hi Mike,

Thanks for your reply, but sadly this doesn't do the trick for me. I'd have to explain a bit of why it doesn't though:

The attachment script that runs from the email_client macro, is able to not only add attachments to the email, but also to load attachments from them. One feature request that was brought up was the ability to send a notification via the email_client, with pre-attached attachments to the email, but also have the ability to manipulate them. I used the default functionality of this xml, by adding attachments on the record before the client was loaded (so manipulating the attachments was an option).

I wrote a before insert business rule for this on sys_email, that copies attachments of the ticket to the sys_email record, before serving it to the email_client. I got it to work with the GlideURI (it sends the sys_id of the ticket as parameter as well as the table), but it's not exactly a 'parameter'. I need to substring the URI to get the correct data, so I am able to copy my attachments.

I tested current.instance, but this is sadly not yet available before the time of insert. Also current.target_table is not filled at this time.

I do really appreciate the suggestions and time you took though! Thanks!

Wesley