SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list which contains a number of "Single line of text" types, these can be written with anything the user wants, but should, by default, provide a GUID value.

It seems that one cannot properly create a proper GUID value directly in javascript, so what would be the simplest method for me to automatically populate these fields with a GUID value?

share|improve this question

If you are looking to populate a form instead of providing a default value after an event has occurred you could refer to the following:

As it says these methods generally don't provide true GUID values. What I may recommend instead if you need this is to perhaps create a web service that simply returns a newly generated GUID and combine that with some jquery ajax to get the GUID and populate the field in the form.

share|improve this answer
Good suggestions, although as you say the first isn't really GUID. The web service idea isn't terrible either. But I'm hoping to find a simpler method. – Dave Alger Apr 13 '12 at 12:32

The simples way is to create SPItemEventReceiver and implement ItemAdding, ItemUpdating methods.

share|improve this answer

If your problem is how to obtain a guid in javascript you can render a JS variable to your page from server-side code and populate it with anything you want. You can create a delegate control (here's the step-by-step guide exactly for your task) and do the following:

public class MyDelegateControl : WebControl
        protected override void OnLoad(EventArgs e)

            if (!Page.IsCallback && !Page.IsPostBack)
                string script = String.Format("var myGuid = '{0}';", Guid.NewGuid().ToString());

                Page.ClientScript.RegisterClientScriptBlock(GetType(), "NewGuidsScript", script, true);

If you need 10 guids simply create 10 variables or an array or anything you want.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.