How can I automate creating a change request with a unique document template attached?

frappe
Kilo Expert

Here's the requirement I'm trying to achieve:

When a Change Request is created it's automatically populated with a word document attached (but it has a unique ID).

For example I have a "request for change" questionnaire document template.  

Each time a change is created I want this document to be attached to the change but only associated with this change request.

The Change Owner will edit the document and fill in the information for this specific change.   Ideally the filename should contain the

change record ID number like <CHG12345> Request for Change  

Any thoughts on how best to do this?     Ideally we want to do this with configuration and not customization if possible.

Thanks,

Kristin

1 ACCEPTED SOLUTION

Hi Kristen,



Instead of a "template template", just pick some random record to hold the original attachment. It doesn't even need to be a change record. Let's say for sake of argument that it's on the sys_user record for 'guest' (we'll also pretend that record has a nice easy sys_id of 0123456789ABCDEF.



Now you just need an AFTER business rule on the change request table that looks something like this:



Name: Copy sample doc


Active: true


Insert: true


Update: false


When: After


Condition: (empty)


Script:


(function executeRule(current, previous /*null when async*/) {


        GlideSysAttachment.copy('sys_user', '012345679ABCDEF', 'change_request', current.getValue('sys_id'));


})(current, previous);



//Untested


View solution in original post

9 REPLIES 9

Chuck Tomasi
Tera Patron

Hi Kristin,



When you create the new change request, use an after business rule to create a copy of the attachment (you'll have to upload an initial template somewhere.)



The key to making this happen is GlideSysAttachment.copy(). You can find more details and example here:



Copy Attachments from Record to Record - ServiceNow Wiki


Hello Chuck,
 
I have one reference field, if I select option from reference column, I want to populate the attachment and download the attachment.  If I select different option from the reference, I want to be able to download the different attachment. Once user download the attachment, user can needs to edit the attachment and update the attachment in same record and its need to update in same attachment with sysId and content type. 
 
I'm try it in Custom Application, please help me with the same. 
 
Thanks  in Advance ,
 
Regards,
RDK.

I was with you until the end. If the user is downloading a file and editing it, when they upload, they are going to be uploading a new file. There's no current way to "replace" the existing upload by default. You would need to build some logic to say "Hey, that file has the same name" or "Here comes an attachment, let's automatically delete the existing attachment(s)". Both of those sound really scary to me. It sounds like you might be getting in to functionality found in the Employee Document Management plugin.

Employee Document Management

Hello Chuck,

Thanks for your response, 

I have installed plugin in personal instance, i have no idea how to use this 

Employee Document Management for my requirement.

Thanks in advance!

 

Regards,

RDK.