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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Kristin,



As you mentioned that each time change owner will make a edit..It means a download, edit followed by upload which will again create record in change request against this specific record only.


In this case you can have static template attached for all the change as change owner will make a edit and upload.(This will take care of attachment to be unique for each change request).



Please let me know if you have any questions.


Hi



I've spent hours researching here and the internet trying to figure out how to do this and not getting anywhere.     I've tried various methods folks are using and keep hitting dead ends.



1) First hurdle: I can't create a change_request template (not incident) with an attachment on it.   How do I get that to work?   (I tried saving a form as a template too but still attachment didn't save)



Also:   Many methods I could find mention this:   You'll need to create a field called 'Template (u_template)' on any table that you want to apply templates to. The field needs to be a reference field that references the 'Template (sys_template)' table.       (In my Dev instance this doesn't work because sys_template is not available in the dropdown as a Reference field)






Thanks,


Kristin


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


Awesome !   That worked.      


You're welcome. Care to mark my answer correct so others with the same question or issue can find it easily in the future?