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

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!

Hi, Allen,

Interesting. No, I have not tried but will try it. Stay tuned.

Thanks for the reference.

 

Hi,

Ok. Glad my replies have been helpful to gain more information and then allowed me to try and suggest a no-code solution that uses the same flow you're already in where you have access to both record sys_ids.

 

If my reply above helps guide you Correctly, please consider marking it as "Accept Solution".

Thanks!


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

Hi,

It looks promising and I agree that a no-code solution is best.  However, I'm running into an issue where the target record is not available in the flow. 

MollieV_0-1680108937594.png

The Create Business App action that creates the target record does not return the sys_id. This is oob script that it executes.

MollieV_1-1680109091284.png

 

I might have to add additional actions such as Lookup the newly created cmdb_ci_business_app and get the sys_id that way? I'm new to Flows and still trying to figure out the best way use it.

 

 

Hi, Allen. I just want to close the loop on this. The Copy Attachment is not as straightforward as described.

I ended up executing a Lookup Attachment action, followed by a Look up record to get the attachment record, then use the attachment record as the source for the Copy Attachment action. It wasn't taking the business_app_request record as the source and was giving an error.

This is what it looks like and it's working as expected.

MollieV_0-1680116623847.png

 

Thank you for your help and guidance.