Autofilled Sharepoint’s Form

Indonesian:

Dalam tulisan tentang “Multiple Attachment in Document Library” ada satu screenshoot yang sering ditanyakan.

Upload Attachment

Didalam screen shoot tersebut dapat dilihat bahwa field “Main Library” terisi secara otomatis. Selain itu sebagai informasi tambahan, field yang sudah terisi dengan http GET berubah menjadi read-only.

Bagaimana cara membuat field entry yang dapat terisi secara otomatis?

English:

In my posting about “Multiple Attachment in Document Library” , some friends questioning one of the screenshoot.

Upload Attachment

In that screenshoot, we can see that “Main Library” field is automatically filled. In addition, the field became read-only but leaving the other un-filled field editable.

How can we create autofill Sharepoint’s form?


Indonesian: (see English version)

Ada banyak cara yang dapat digunakan untuk mewujudkan kebutuhan diatas, misalnya dengan ASPNET, custom control dll. Namun, penting untuk diingat bahwa kita bekerja dengan SharePoint. Sharepoint itu sendiri memiliki filosofi untuk meringankan pekerjaan-pekerjaan coding. Oleh karena itu, solusi berikut ini dilakukan dengan memanfaatkan semaksimal mungkin fasilitas yang ada di Sharepoint.

Modifikasi Upload.aspx secara global

Autofill dapat ditempatkan di halaman masukan mana saja, seperti NewForm.aspx, EditForm.aspx. Namun sesuai dengan gambar diatas, maka kali ini kita akan melakukan modifikasi pada halaman Upload.aspx. Modifikasi dapat dilakukan di masing-masing Document Library dengan menggunakan FrontPage untuk mendapatkan efek hanya di Document Library tertentu saja. Sebaliknya, untuk mendapatkan efek secara global, maka perubahan harus dilakukan di template yang dirujuk oleh site.

DocLibrarySchema

Kali ini perubahan akan dilakukan di skema Document Library yang ada di template STS.

c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\STS

Disana kita akan menemukan folder LIST/DOCLIB, dan didalamnya dapat kita temui file-file sepert Upload.aspx , EditForm.aspx dsb.

Buka file Upload.aspx dengan menggunakan editor teks, kemudian tambahkan javascript yang berguna untuk membaca variabel http GET. (Contohnya, RequestVars.js yang bisa diambil dari internet.)
Saya sendiri menempatkan file RequestVars.js di folder

c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033

kemudian menempatkannya di Upload.aspx dengan script,

<script src=”/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/RequestVars.js”></script>

Perhatikan bahwa <%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%> berguna untuk memperoleh kode bahasa yang digunakan oleh site. (Default: 1033)

Parameter yang diperoleh dari http GET akan disimpan didalam array asosiatif _GET. Kemudian dilakukan pengecekan key didalam _GET bersesuaian dengan nama field didalam Document Library / List. Jika sama, maka field tersebut akan diisi dengan nilai (value) yang ada dan isinya diproteksi dengan membuat field tersebut read-only. Isi javascriptnya bisa dilihat langsung pada gambar dibawah.

UploadAspx

Setelah selesai, simpan file Upload.aspx dan lakukan iisreset dari command prompt. Perubahan diatas akan langsung bisa diuji-coba pada proses upload di semua Document Library (kecuali, Document Library dengan file Upload.aspx yang pernah diedit dengan FrontPage 2003).

Pengetesan

  1. Buat Document Library baru dengan nama TestDocLib
  2. Modifikasi elemen field dengan menambahkan field baru bertipe string, “InfoField”
  3. Coba panggil halaman upload dari TestDocLib
    http://[WebSiteName]/TestDocLib/Forms/Upload.aspx?RootFolder=&InfoField=TestInformation

Dan kita akan memperoleh halaman Upload dengan field “InfoField” yang sudah terisi dengan text “TestInformation”.

Proses diatas dapat dilakukan pula di halaman-halaman masukan yang lain, seperti EditForm, NewForm dsb.

— o0o —

English: (dalam Bahasa Indonesia)

There are many possible ways to create the solution, for example using ASPNET, custom control etc. However, we must remember since we are working with Sharepoint, then we must exploits all Sharepoint’s capabilities. The Sharepoint itself have a basic philosophy to make web publishing closer to the business users; hence avoids to create custom code – but maximize its ability.

Modify Upload.aspx globally

Autofill form can be placed in any entry form such as NewForm.aspx, EditForm.aspx. Our example here will modify Upload.aspx – as our question start on that page. Upload.aspx can be modified individualy in every Document Library to create special effect in desired Document Library. However, to achieve global effect, the modification must be performed in the template referenced by Sharepoint site.

DocLibrarySchema

This time, we are going to modify Document Library schema in STS template. Usually in the following folder,

c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\STS

In that folder, we can find components that build STS template. One of them is LIST/DOCLIB which constructs Document Library. Going further inside LIST/DOCLIB folder we will find Upload.aspx , EditForm.aspx etc.

Open Upload.aspx using text editor, and add additional javascript to read http GET variable. Put the script just before </HEAD> tag. You can make it yourself or grab it online from internet. In this case, I put RequestVars.js in Sharepoint common folder,

c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033

and then load it into Upload.aspx using script tag,

<script src=”/_layouts/<%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%>/RequestVars.js”></script>

Notice that <%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%> is a server side script to create site language code. (Default: 1033)

Values from http GET will be put in associative array _GET. We create another function to check all keys in _GET and compared with field name in Document Library / List. If it found the same name, then we use DOM to fill field value with the value from _GET. We also protect the field so it won’t be editable anymore. I am so lazy to write the script again, so examine from the picture below.

UploadAspx

After finish all script, save Upload.aspx and do iisreset from command prompt. The changes will globaly applied to all Document Library (except, the ever edited Upload.aspx using FrontPage 2003).

Testing

  1. Create a new Document Library named “TestDocLib”
  2. Modify the field by adding new string field named “InfoField”
  3. Try to test the new upload page from TestDocLib
    http://[WebSiteName]/TestDocLib/Forms/Upload.aspx?RootFolder=&InfoField=TestInformation

And we will have Autofilled Sharepoint’s Form, in this case “InfoField” value should be “TestInformation”.

All process can be replicated to other entry from such as EditFrom, NewForm etc.

About

Riwut Libinuko, experienced Architect. Currently working with Credit Agricole CIB, responsible for SharePoint platform in Asia Pasific. . Certification: SharePoint 2013, SharePoint 2010, SharePoint 2007, ITiL v3

Posted in Microsoft Sharepoint, Tips and Tricks
One comment on “Autofilled Sharepoint’s Form
  1. Suleman says:

    Hi Cakriwut,

    I’m facing problems with AutoFill properties on NewForm and EditForm of Lists and Document Libraries. I tried to read your code from the picture but I couldn’t. Can you please mail me this Code so that I can get a clear Idea how can I achive this task.
    Thanks in Advance.
    Email Address: suleman.ibrahim@konvergeandknow.com

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: