How to create a new Document Revision record associated to Document record automatically when a new Document record is created ( Managed Docs).

Servicenow Stud
Mega Contributor

Hi All,

I am creating a new Document Record, when a custom table record gets closed. But I also want to create Document revision record associated to respective Document created. For this I used flow designer that triggers when a document record is created. This is creating new Document revision record, but is not showing any relation with Document record. How to create a document revision record associated to respective document record created.

find_real_file.png

find_real_file.png

find_real_file.png

 

Thanks

1 ACCEPTED SOLUTION

Are you attaching attachment on those fields after record creation. 

You can write after update business rule on custom table, condition you can include

"field changes"

and then use that script to copy the attachment from custom table to revision table. 

 

In business rule you have to get the revision record sys_id by glide record , i am assuming in your custom table you are storing "Document Revision" record , or storing custom table record in "Document Revision" form ? 

 

 

 

View solution in original post

11 REPLIES 11

Servicenow Stud
Mega Contributor

Hi  @Ankur Bawiskar , @Chuck Tomasi , @Pradeep Sharma , @Mark Roethof , @Harshvardhan ,

Could any of you please help me on this. This Managed Doc is really confusing, I need your help here.

Thanks

Harsh Vardhan
Giga Patron

You have to add Document record sys id on document revision column "Document", this way your document revision will link to the document record. 

Hi @Harshvardhan ,

Thank you so much, that is working. I have one more requirement, like copying attachment stored in a field of custom table to this document revision record. 

1. I have written before insert/update business rule to create document record when the custom table record gets closed.

2. I have created a custom string field "Created from" on Document table, which is update by BR written like "Record Created from script".

3. I have created Flow designer, which triggers when Document record is created and with if condition, Created from is "Record Created from script". So with all these steps I am successfully able to create Document record and Revision record associated to respective Document Record. Now I want to copy the attachment on a field of custom table to this Document Revision Record. Could you please help me on this, as I am not able to find much information on this specific document application.

Thank you.

You can use GlideSysAttachment copy() method to copy it from custom table to "Document revision" record. 

Script Example:

 

GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id');

 

Doc Link.

Useful attachment scripts