Help with Business Rule attaching a file from the business app request to business application

Mollie V
Tera Guru

Hi,

I was advised by HI support to create a before insert business rule to copy attachments from the Business Application Request record (business_app_request) to the Business Application (cmdb_ci_business_app) record using the following script. HI provided this reference GlideSysAttachment | ServiceNow Developers.

It works great when I know the sys_id.

 

var source_sysId = '1d3aca2e1bb5a9503c5f97d4bd4bcbe6';

var gr = new GlideRecord('business_app_request');
gr.addQuery('sys_id', source_sysId);
gr.query();
while (gr.next()) {
Packages.com.glide.ui.SysAttachment.copy("business_app_request", gr.sys_id, "cmdb_ci_business_app", current.sys_id);
}

 

The business_app_request is created from a catalog request and the flow creates the cmdb_ci_business_app. Since copying the attachment is not standard functionality, I need to create a BR to do this.

Can someone clarify how to access the source record, in this case the business_app_request that is created from the catalog request, to get the attachment sys_id?

 

Thanks,

Mollie

2 ACCEPTED SOLUTIONS

Hi,

Are you able to insert the copy attachment action as part of this flow? Where you have access to both the sys_id for both the business app and the cmdb_ci_business_app?

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/flow-designer/reference/... -- this can be done without code and just dragging the relevant pills to the configuration.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

Hi @Mollie V 

The copy attachment action is pretty straightforward, you just needed to have access to the objects/records for the inputs. Without looking directly at your flow and without seeing all the inputs to it (you had the inputs cut off in your screenshot in your last reply), I couldn't see if there was something else you could utilize (such as setting a flow variable to the sys_id, etc. and then using that instead).

 

In any case, the point was to use a no-code option, if you can, and not use a business rule which you were stuck on anyway because you didn't have the sys_id you needed. So in either case, some sort of lookup most likely would have been needed.

 

In the end, great work and I'm very happy to see that you took what I recommended and then ran with it and achieved success.

 

If possible, please review this thread and consider marking any reply as Helpful, if it was and if my reply that guided you towards the Copy Attachment action helped resolve your issue, please mark that as "Accept Solution". I'd also recommend you also mark your last reply here as "Accept Solution" as well (as you can mark more than one as accepted).

 

Great work! and take care! 🙂


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

10 REPLIES 10

Allen Andreas
Administrator
Administrator

Hello,

Could you not reply back to ServiceNow to ask them this to close the loop on your case you had open?

If the business rule is running on the business_app_request then you're copying it from the current record, aka current.sys_id.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks, Allen, for your reply. 

The business rule is running on the cmdb_ci_business_app. This is the record that I need the attachment copied to from the business_app_request record. 

 

Here is the setting for the BR.

When to Run: before insert

Table:  cmdb_ci_business_app

Script:

var source_sysId = '1d3aca2e1bb5a9503c5f97d4bd4bcbe6';

var gr = new GlideRecord('business_app_request');
gr.addQuery('sys_id', source_sysId);
gr.query();
while (gr.next()) {
Packages.com.glide.ui.SysAttachment.copy("business_app_request", gr.sys_id, "cmdb_ci_business_app", current.sys_id);
}

 

Appreciate the help.

Mollie

Hello,

Yes, we saw your script in your original post.

The issue is, we aren't clear what the chain of events are for what you're doing. If you have a catalog item that is creating the business app request request, how/when is the cmdb_ci_business_app record being created? What is causing that to happen?

 

You'd have to think through those chain of events and understand when you know both the record sys_id for the business app record and the sys_id for the cmdb_ci_business_app record.

 

Is this part of an APM flow? Can you give more information?

 

Also, it's still recommended to simply continue working with ServiceNow since you already had a case open for this and were talking to them.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

This is the flow, and yes this is part of the APM flow.

 

A user submits the Register a Business Application catalog request with an attached file. This triggers the register_business_application flow and executes the create_ba action where the input form fields are mapped and saved to the cmdb_ci_business_app record. This runs the oob script ManageBusinessApp (API name sn_apm.ManageBusinessApp) that ServiceNow support helped fix because there are missing fields that we needed to save from the input form.

 

Unfortunately, they closed the case because they said copying the attachments is not oob functionality and that we had to write a custom business rule if we want the attached files from the request copied to the cmdb_ci_business_app.

I was trying to do make this work before opening another case with support.

 

Thanks.