My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

20 January 2008

How to set default values based on a query string and make those fields uneditable

by Patrik Luca 72 comments

Tag



Introduction

 

I found an interesting post of Rob Howard: Using Javascript to Manipulate a List Form Field. It describes how you can set default values based on the query string.
I started playing around a bit with it and elaborated a case more in detail.


Business Scenario

I have a list with items, which can be ordered. Each item has a price and belongs to a category.
Next to each item, I want a hyperlink: clicking on it will open a window where the end-user can give in the quantity the user wants to order for that item. I want to pass to that window the title, the category and the price of the item. As such, these fields are available for searching, sorting and so on in the transaction list. Off course, I want to avoid that the end-user has to give in again the price and the category of the item. Moreover, the end-user shouldn't be able to manipulate these fields.


Custom list with items
  • Title column
  • Category column (choice)
  • Price column (currency)



Custom list with transactions
  • Title column
  • Category column (choice)
  • Price column (currency)
  • Quantity column (number)



Solution: Use some Javascript

  1. Open the AllItems.aspx page in Microsoft Office SharePoint Designer 2007.
  2. Right-click on the ListViewWebPart and choose Convert to XSLT Data View.


  3. Right-click the last column and choose Insert -> Column to the Right


  4. Right-click in a cell of the newly added column and choose Hyperlink.


  5. Enter the text you want to set as hyperlink in the Text to display and enter the address to the NewForm.aspx page of your transactions list. Additionally add the parameters you want to pass. In my case, it results in an address of: ../Transactions/NewForm.aspx?Title={@Title}&Category={@Category}&Price={@Price}. Hereby is the part to the left of the = free to choose, the part to the right of the = is the name of your column within {@}.


  6. Re-open the Items list: there will be a hyperlink available on each line. Clicking on it will redirect you to the NewForm.aspx page of the transaction list, and you pass to it some parameters through the querystring.


So far, so good. Now we still need to fill out the values based on the values in the querystring, and set the fields uneditable.

  1. Open the NewForm.aspx page of the transactions list in Microsoft Office SharePoint Designer 2007.
  2. Add following code right after the opening PlaceHolderMain tag within Javascript script tags:
    _spBodyOnLoadFunctionNames.push("fillDefaultValues");
    function fillDefaultValues(){
    var qs=location.search.substring(1,location.search.length);
    var args=qs.split("&");
    var vals=new Object();
    for (var i=0; i<args.length;i++){
    var nameVal=args[i].split("=");
    var temp=unescape(nameVal[1]).split('+');
    nameVal[1]=temp.join('');
    vals[nameVal[0]]=nameVal[1];
    }
    var title=vals["Title"];
    if(title==undefined)
    return;
    var theSelect=getTagFromIdentifierAndTitle("select","Lookup","Title");
    if(theSelect==null){
    var theInput=getTagFromIdentifierAndTitle("input","","Title");
    if(theInput==null){
    return;
    }
    theInput.value=title;
    document.getElementById(theInput.id).readOnly=true;
    }
    else{
    theSelect.value=title;
    document.getElementById(theSelect.id).readOnly=true;
    }
    var price=vals["Price"];
    if(price==undefined)
    return;
    var theSelect=getTagFromIdentifierAndTitle("select","Lookup","Price");
    if(theSelect==null){
    var theInput=getTagFromIdentifierAndTitle("input","","Price");
    if(theInput==null){
    return;
    }
    theInput.value=price;
    document.getElementById(theInput.id).readOnly=true;
    }
    else{
    theSelect.value=price;
    document.getElementById(theSelect.id).readOnly=true;
    }
    var category=vals["Category"];
    if(category==undefined)
    return;
    var theSelect=getTagFromIdentifierAndTitle("select","DropDownChoice","Category");
    if(theSelect==null){
    var theInput=getTagFromIdentifierAndTitle("input","","Category");
    if(theInput==null){
    return;
    }
    theInput.value=category;
    freezeValue(theInput);
    }
    else {
    theSelect.value=category;
    freezeValue(theSelect);
    }
    }
    function setSelectedOption(select,value){
    var opts=select.options;
    var l=opts.length;
    if(select==null)
    return;
    for(var i=0; i<l; i++){
    if(opts[i].value==value){
    select.selectedIndex=i;
    return true;
    }
    }
    }
    function getTagFromIdentifierAndTitle(tagName,identifier,title){
    var len=identifier.length;
    var tags=document.getElementsByTagName(tagName);
    for(var i=0;i<tags.length;i++){
    var tempString=tags[i].id;
    if(tags[i].title==title && (identifier=="" ||
    tempString.indexOf(identifier)==tempString.length - len)){
    return tags[i];
    }
    }
    return null;
    }
    function freezeValue(tag){
    var chosen=tag.options.selectedIndex;
    tag.onchange=function(){
    tag.options.selectedIndex=chosen;
    }
    tag.className="ms-MenuUIItemTableCellDisabled";
    }



  3. Reclick the Order hyperlink on the Items list: your values will be filled in automatically on the transactions NewForm.aspx page and they will be uneditable by the end-user.










Some extra explanation:


For the functions fillDefaultValues, setSelectedOption and getTagFromIdentifierAndTitle: see Using Javascript to Manipulate a List Form Field.





Text fields can be set uneditable by using following code: document.getElementById().readOnly=true.





Choice (drop-down fields) cannot be set uneditable. To solve this, I created the function freezeValue.


This function resets each time an end-user clicks the drop-down box to its initial value: as such the end-user won't be able to post the form with another value than the one filled in by default by the values of the querystring.


To make it somewhat more userfriendly, I used a class of the SharePoint default css files: as such the drop-down box is grayed out, making it already somewhat clearer for the end-user that touching it makes no sense.

Comments 72 comments
Anonymous said...

How about for multi checkbox?

Anonymous said...

nice post, but how to use this with multiple lookup fields?

thanks

Soudip Biswas said...

hi!!
hey need your help urgently.
I tried out your script but it didn't work for me.
My suspision is that i am not sticking the script in the right place.U suggested it to append in MainPlaceholder...but i cudnot find this tag in my code view(using Frontpage03)in the file newform.aspx.....please tell me wher can i insert this script to make it work...an early response will be highly appriciated coz am nearing my deadline...am in despair

Patrik Luca said...

You should find a line like this: <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

Put the script right after this line between <script type="text/javascript>code comes here</script> tags

Anonymous said...

Hey Patrik,
Thank you very much for taking out time from your busy schedule to attend my query..
but you know, i still cannot find that tag..
i tried inserting the script in..
"WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"

but didn't work...
I am using Sharepoint portal 2003..
Is this the reason behind me not finding the apt tag...??
if yes,how can i make it work for SPS03 version???please help

Patrik Luca said...

Sorry Soudip,

the example posted here is for WSS 3.0 or MOSS 2007.

I don't know the solution for SPS2003.

Jase said...

Hi, I'm using MOSS2007 and have followed your example. I even created 2 lists like yours. The script does execute on load but the fields arent populated with the values passed in the query string.

Any ideas?

Patrik Luca said...

Hi Jason,

very difficult to say what is going wrong in your case. I would suggest you try to do some debugging. You could add the alert function in between the different steps to see which parameters are filled up by the script. In my example, you could f.e. for the price part add following lines of code each time after the line where the variable is assinged a value:

alert (price);
alert (theSelect);
alert (theInput);

Upon loading your SharePoint page containing the Javascript code, alert boxes will appear with the values for each variable. Maybe this can help you further to investigate where your problem is situated.

Anonymous said...

NOT WORKING FOR ME... :(

I followed all the steps but still DON'T POPULATE...

Please... Please H E L P!

THANKS IN ADVANCE...

SPbb said...

Hi Jason,

I am using WSS 3.0....

Why don't populate....

You found it why? :)

Thanks

Patrik Luca said...

Hi,

can you provide me more details what error messages appear (if there appear messages at all...). Did you try out with the alert messages to see where variables are filled or where not?

SPbb said...

Hi,

I aready found the problem to the code... the missing l of null in the price part condition..

Thanks a lot Patrik your code really help me!

Keep up the good work.. WISH YOU LUCK!

SPbb said...

One more question Patrik if you don't mind.

How do I set the cursor posion?

Any Idea?

Thanks

Patrik Luca said...

Hi SPbb,

I've never tried it out myself, but I guess something like
document.getElementById(theSelect.id).tabindex=1;
should do the trick whereby:
* 1 is the place of order in which the cursor will be set upon tabbing
* theSelect.id the id of a text-input field on your form

But as said, I've never tried this out myself, so I am not sure.

SPbb said...

Hi Patrik,

I'll gonna try that later today :).

Thanks for the quick reply I really appreciated it.

I found problem in setSelectedOption function.

return = true; / return true;

Thanks a lot!

SPbb said...

Another quick question Patrik :?

is it pasible after clicking ok button/cancel it will go back to the item main page? any idea?

THANKS!

SPbb said...

how do I combine the First Name and Last Name to become a full name..

FullName = Lastname, FirstName

Any idea?

Thanks

Patrik Luca said...

Hi SPbb,

thanks about mentioning the problem in the setSelectedOption: I've updated the post with it.

Thanks.

Patrik Luca said...

Hi SPbb,

about your question how to set the cursor position. This can be achieved by adding following code:

var theInputFocus = getTagFromIdentifierAndTitle("input","","fieldyouwanttosetthecursorto");
document.getElementById(theInputFocus.id).focus();

Patrik Luca said...

Hi SPbb,

Are Lastname, FirstName and FullName Javascript variables?

If so, you can concatenate Lastname and Firstname into the Fullname variable by adding this line of code:

FullName = Lastname + FirstName;

Patrik Luca said...

Hi SPbb,

to redirect to your item main page after clicking the OK button, add following query string parameter in step 5 where you have added the parameters to be passed to the NewForm.aspx page:

source=yourpathtotheitemmainpage/allitems.aspx

So you'll have a hyperlink like
../Transactions/NewForm.aspx?Title={@Title}&Category={@Category}&Price={@Price}&source=yourpathtotheitemmainpage/allitems.aspx

SPbb said...

Hello Patrik,

Big thanks for your reply... :) saves me a lot of time googling around! They works great!

The FullName is not a Javascript variables. It is a data entered by the user. Is there a Java Script that will do that? it will automatically fillup the FullName after entring LastName and First name?

I like your freezing function but I cannot manage to freeze my DROPDOWN list LOOKUP that has more than a hundred records on it. Pulling my hair again and still does'nt. Any idea why?

I LOVE YOUR BLOG!!!! You are the MAN!

Patrik Luca said...

Hi SPbb,

thanks for your positive feedback about my blog: spread the word I would say ;-)

About the FullName: I would suggest you use a calculated field for this: as such this field will be automatically field when the user enters a value for LastName and FirstName.

You can find some great examples, exactly (coincidence...) for filling out automatically the FullName on: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx. Look for the text formulas and the examples about combining first and last names.

Patrik Luca said...

Hi SPbb,

if yout dropdown list lookup has more than 20 values, than you should use a function for this, as it is rendered on another way by SharePoint.

Add the function beneath to your NewForm.aspx page in the javascript tags.
And do a call to the lookup column with it (suppose your lookup column is called Product):

setLookupFromFieldName("Product", vals["ID"]);

function setLookupFromFieldName(fieldName,value) {
if (value == undefined) return;
var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element
if (theSelect == null) {
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
ShowDropdown(theInput.id);
var opt=document.getElementById(theInput.opt);
setSelectedOption(opt,value);
OptLoseFocus(opt);
document.getElementById(theInput.id).disabled = true;
} else {
setSelectedOption(theSelect,value);
freezeValue(theSelect);
}
}


However: I must admit: it is not really freezing it: it only seems as such: the end-user can still change the value: I didn't found a solution for this neither. If somebody finds it, be my guest to post it here.

SPbb said...

Hello Patrik,

The samples links that you gave me helps me alot!

I'm still googling around to find a way how to totally freeze that.. If I can found one I will really post it to this cool blog of yours.. :)

One more question here :)
Do you have any idea how to highlight the selected row on datalist? The conditional formatting seems not working. Is there a way to do that? it very nice if it will highlight the whole row when you point the mouse pointer to it then it will remain higlighted as the selected row after clicking..

Thanks in advance Man! Your help is really appreciated!

SPbb said...

Hi Patrik,

I found this site and looks interesting too.

http://splittingshares.wordpress.com/2008/06/11/web-application-design-part-1/

This line of code part seems not working for me.

if test=”$CurrentRowKey = $dvt_curselkey”>background-color: #ffffe0;

Any idea why?

THANKS

Patrik Luca said...

Hi SPbb,

I have not yet experimented a lot with conditional formatting, so I am afraid I won't be able to help you.

SPbb said...

Thanks anyways Patrik!

I'll just continue googling the net hoping I can find easy one how to do that datalist selected row highlighting.

:)

Csam0003 said...

Hi,
For some reason the values are not beign passed through the url. Basicall In SP Designer, I right clicked on a button then clicked on Form Actions. I entered the url to be re-directed to upon clicking the button and some parameters to pass.
Any ideas what's wrong?

Thank you
Regards
Chris

Patrik Luca said...

How does the url exactly looks like once you are on the page to which you are redirected?
Does it has the query string values, it is http://...?a=%201&b=%201c=

In other words, your query string is present in the url of the redirected page, the variable names are there, but their value is empty?

If the latter is the case, did you put brackets around the value on the page from where you are redirecting throug an url, it is did you put {@value}?

If so, on your page where you are doing the redirect, add a javascript function which calls an alert box in which you are displaying the value of your parameter to see if it is available and not empty on your page from which you are doing the redirect.

Csam0003 said...

Hi Thanks alot for your promt reply...

Basically the url looks like this when I'm re-directed: http://cs2/MarketPlace/Lists/Contact%20Form/NewForm1.aspx?ID={@ID}

I added a javascript to display the value and it is empty!

Any reason why?

My email address is: sammutchris@gmail.com

Patrik Luca said...

Open the page containing the redirect url in Microsoft Office SharePoint Designer 2007 in code view and search for the <DataFields> node. Here you'll find all available DataFields on the page: do you find @ID in the listed DataFields?

Csam0003 said...

Good morning,
Yes, the @ID is there!
The funny thing is now I tried. The code for the button is:
input name="Button3" type="button" value="TEST" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={../Contact Form/NewForm1.aspx?@Title_x003D__x007B_@Title_x007D_&@Author_x003D__x007B_@Author_x007D_}')}"/

Maybe that might help?!?!

Thanks

Chris

Anonymous said...

Can you advise if this will work on content types that are within the same list, I would like to pass information from one content type to another without the user having to repeat it.
Pampvkjahe

Patrik Luca said...

Yes this should work on content types in the same list: a column with a hyperlink to the same list with as query string parameters ContentTypeId=value with value equal to the content type id of your second content type in the list. You can add other query string parameters which you can parse in the NewForm.aspx of the list. You'll have to add some logic that these values should only be parsed and applied to default values for the second content type if there is a query string parameter ContentTypeId (this to avoid that some parsing is tried for the first content type, which shouldn't be done, or which would else result in errors: remember that the NewForm.aspx is used for BOTH content types in the same list...)

Anonymous said...

Hi Patrik, I have a query....I have my list prepulating with queries and working well. However, I have a lookup list which is coming over in the query and populating the list with the drop down options, but it is not setting it to the option in the query. This is the code I used. My field name is Client Name and the query value is Client Name. Can you advise why it is not setting the lookup field.

setLookupFromFieldName("Client Name", vals["Client Name"]);

function setLookupFromFieldName(fieldName,value) {
if (value == undefined) return;
var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element
if (theSelect == null) {

var theInput = getTagFromIdentifierAndTitle("input","",fieldName);

ShowDropdown(theInput.id); //this function is provided by SharePoint

var opt=document.getElementById(theInput.opt);

setSelectedOption(opt, value);

OptLoseFocus(opt); //this function is provided by SharePoint

} else {

setSelectedOption(theSelect, value);
}


Pam

Patrik Luca said...

Hi,
Your code should work like a charm. I guess the problem is in your field name and query value name. I doubt if you are using the correct ones: in the cases where you name a field with an space in it like "Client Name", SharePoint will translate it in the DB as something like Client_0x0020_Name. To get to know how your created field is really stored in the content DB, follow the instruction as desribed in the Find the Additional Data part of this blog article.

To debug, I advice you to throw some alerts with your field and your query value to see if it is coming in correctly in the first place: which I think is your current problem now.

Anonymous said...

Hi!
I have a problem connecting two data views in Sharepoint designer, maybe someone can help me.

I have two lists:
Products (it should not be changed), that contains the following fields, for example:
Customer, Model, Price.

Transaction, that is empty to start. The fields are: Invoice, Customer, Model, Price, Quantity, Amount(calculated: Price*Quantity)

I created two data views on the webpart page.
Products view, as multiple data view and transaction view as New Data View.

On the Products view I created a column with the hyperlink “order”.
The “order” was set up with the following steps from WebPart connections:
Source web part – products, source action – send row of data,
(connect to webpart on this page selected)
Target web part – transaction, target action – get filter values from (I used “get parameters too, but with the same results)
Selected matching columns (Customer, model, price)
Create a hyperlink: current selection, did not check “indicate current selection”
I’d like to pass the Customer, model and price from one web part to another, but the receiving webpart has blank fields. What am I doing wrong? Is it possible?

I also need generate a number in Invoice field. Do you have any idea how to do it?
Thank you.

Patrik Luca said...

To generate a number in the invoice field, you could develop a custom workflow with SharePoint Designer (I guess your problem now is that you cannot use the ID field, as your invoice number most likely will to have a certain format etc.).

Anonymous said...

Thank you for your nice work!!

Pingback from http://vallimarco.spaces.live.com/blog/cns!F59AF3AD6493A526!240.entry

Anonymous said...

Hi

Just like to draw your attention to the fact this page doesn't render correctly in Firefox! The text about the business scenario disappears behind the right column, so you can’t read it correctly.

Anonymous said...

Hi

nice post, it is working to me, but i have a problem :

Title field IS editable and I implemented as our code from this page. Price is uneditable.

I used the same lits.
I am using Wss3.0 (Pt,Pt) - Portugues

Any sugestions ?

Thank you for you help

Anonymous said...

Patrik,
Could you possibly define your script for different elements? I am trying to modify it to fit my list but am not sure what all elements are in there.

Thanks,
EH

Patrik Luca said...

I am really sorry, but I don't understand your question. If you could clarify it a bit, I will be glad to help you out (at least to give it a try)

Anonymous said...

No probs.... In your script you have the Title field being defined. If for example my field name is "Task", how do I modify the above script to fit my field? I tried replacing the Title, but it wasn't populating anything when I refreshed and clicked on the link.

my url looks like this
/Lists/Register/NewForm1.aspx?title=ASI

I want to set the field on the new form to "ASI" as default
Thanks

Patrik Luca said...

I would set my url like .aspx?Task=ASI (but that is not necessary, but just to make it more transparent)

The Javascript should look like this then (if the Task field is a single line of text field AND if the text you see in front of the input field you want to populate automatically equals Task)

var title=vals["Task"];
if(title==undefined)
return;
var theSelect=getTagFromIdentifierAndTitle("select","Lookup","Task");
if(theSelect==null){
var theInput=getTagFromIdentifierAndTitle("input","","Task");
if(theInput==null){
return;
}
theInput.value=title;
document.getElementById(theInput.id).readOnly=true;
}
else{
theSelect.value=title;
document.getElementById(theSelect.id).readOnly=true;
}

Anonymous said...

Thanks, I took a look at your script and added just that into the form and it still would autofill when I clicked on the link.

Does the link have to be apart of a view from that list? I currently have an icon that I am linking to the New Form. When a user clicks on the Icon, I would like for them to open the newform.aspx and the name in the url to be inserted into the Task Name Field....

Patrik Luca said...

No need to be a part of a view. Just keep in mind that you should be able to give values with your url based on an item in the list, so you should have your list somewhere. If you put for example a button with a url behind it, it should work too. About adding a button: see my example Extension to the Rooms and Equipment Reservation application template

Anonymous said...

Great post.

One question though, I'm trying to pre-populate a multi-line text field (which contains hard returns). I'm using the "TextField" identifier to do this, but it's returning a blank value. If I change the field types to single line text field the target field is populated correctly.

Any ideas what I'm doing wrong?

Patrik Luca said...

I have to disappoint you: I haven't tried my code with multi-line text fields.

Anonymous said...

I managed to accomplish this as follows:

var theSelect=getTagFromIdentifierAndTitle("TextArea","","Address");
if(theSelect==null){
var theInput=getTagFromIdentifierAndTitle("input","","Address");

Unknown said...

Awesome post, Patrik.

I have an issue where the mult lines (>20) is displaying 2-3 inches (blank lines) below where they should. Any ideas? Is this the same issue as above?

Thanks!!

Patrik Luca said...

I'm sorry RobM, I have no ideas about your issue.

Anonymous said...

hi Patrik,
I found your article 2 days ago and I tried to test the code. I do not know javascript, but I really need this code.
My newform page displays the error NullReferenceException: Object reference not set to an instance of an object.]
to Microsoft.SharePoint.WebPartPages.WebPartResultSet.get_FormType ()
to Microsoft.SharePoint.WebPartPages.SPWebPartManager.FixupListWebParts (WebPart part, Type type, Boolean IsClosed)

I followed your advice and put the alert () everywhere.

It seems that the variable "title", "categories" and "price" are not set correctly

Can you help me?
thanks!

Patrik Luca said...

What do you mean with: not set correctly? If you put an alert to show their value: it is null? Or what is shown in the popup alert window for those values throughout your code?

KatiST alias Anonimous said...

variables are "undefined"...
I found the origin of the error message: bad copy and paste, but now my alerts do not work, as if the javascript code does not run in the opening newform
Desperate ...

Patrik Luca said...

How do you know the variables are undefined if your alerts don't work: how do you get to know their value then?

Unknown said...

Hi Patrik,
i was wondering which allitems.aspx form you are altering since you have two different list. i am working on a project which requires to pre populate the fields just like what you have done here. please help this is urgent.
i have Equipment Id and i have to populated department name and no based on this equipment id.
ok here is the full description
1] equipment list:
equipment id
department Number
department Name
start Mileage
2] mileage report:
equpiment id
department Number
department Name
Previous mile
Current Mile
Usage

i also have to prepopulate the previous miles---this comes from the same list -- mileage report---
and user have to enter
current mile and based on previous mile and current mile usage field gets populated

Patrik Luca said...

Hi,

you want to achieve something else than described in my post. In my post I start from one list and I create an entry in another list, starting from the first list. Because I start from some item in the first list, I pre populate some fields in the item I create in the second list.

You want to pre populate a field on an item based on the value you entered for another field on the same item in the same list.

I don't think this is that easy, since you'll probably have to reload the same page, risking to lose your value for your first entered field. I don't have a solution right away for this requirement.

Anonymous said...

Anyone have a version of this page where the text doesn't run under the box on the right? I'd like a version where I could actually read all the text.

Patrik Luca said...

Hi,

use Internet Explorer as browser: you shouldn't experience a problem then to read all of the post.

Unknown said...

Hi,

Requirement: There are two fields.
From- calender type
Effort-Number type

If Effort is entered,From should be readonly and vice versa.

Please help me in this regard

Unknown said...

Hi Patrik,

iam customizing newform.aspx.. i have a requirement where if one field is entered by the user other field should be readonly and vice versa.

Fields are:
FROM-calender; TO-calender
Effort: Number

If user enters FROM-TO, Effort should be readonly and if user enters Effort, FROM-TO should be readonly.

User should enter either of them but not both

Rajesh Pillai said...

Good code.

Anonymous said...

Hi Patrik

Your code works great, however I want to populate a "survey" list with the related ID from another list from an email. So there is a help desk call, that is closed and generates an email with the parameters that need to populate the list. Clicking a link from a list using your method works great but when i try to do something similar using a workflow and putting in the parameters i want in the query string, it passes fine to the URl and the page however it doesn't put the passed string into the boxes

So Take Survey

Passes into the page into the URL but doesn't populate the boxes?

Any ideas how i can accomplish this? I've been scouring google for weeks

Anonymous said...

Sorry "Take Survey" rendered as html should read like a workflow url http://sitename/page/list/newform.aspx?ticket number=[%Help Desk Ticket:ID%]

Anonymous said...

Hello Patrik,

I have tried your code on the same lists as you described (items , transactions) and also i have copied the code after the PlaceHolderMain tag but nothing seems to work, i dont see any change. Also, i tried using the alert option as you said and it didn't do anything, finally i tried to add "debugger;" inside the code and also it did nothing, it seems as the code is not reachable.

I'm hopeless, Do you have any ideas for me?

Anonymous said...

This is a great post thanks!! I have an issue when using a date though, it transfers across like this 2011-02-01T06:00:00Z instead of just the date, even though both list columns are set to date only format, is there something wrong I amd doing in the code Cheers Kris

Anonymous said...

Hi Patrik,
its Kris, I have managed to get a way around this, thought I would share with the page as it helped me a great deal.
What I disabled the form in the 'new form' and made it invisible (this needs to be done so form still has guid available). I then added a custom list form new for the list, on the list form I created a 'parameter' which queried the 'Date' then I changed the date box from a 'list form' to a 'text box', then in the coding I changed this part: id="ff5{$Pos}" text="{@Date}"
to:
id="ff5{$Pos}" text="{$ParamDate}"
click save, then try out the link again, the date comes in as a DD/MM/YYY format, hope this helps others :-)

Ponam said...

Hi Patrik,
I am new baby of sharepoint.Your blog is very helpful for me atleast giving me some kind of confidence that I can do programming on sharepoint.
I have created a list. It has 4 fields including Title. Based on the user selection from dropdown list i want to show only revelant field.Your quick help is appreciable.
list field are title field,dropdown (values IP,TX),Fibre,Peering. I want that initally Title and dropdown are in NewForm.aspx page and when user select IP from dropdown Peering field should be shown to user.
Can you please help me? I need it on urgent basis.

Martin said...

Hi Patrik!

I'm new in Sharepoint, and I need to pass values from a .../AllItems.aspx list to a .../NewForm.aspx

I followed your post, step by step, and tried to adapt your script to my needs, but I failed, and I can't see what the problem is :/
I only need the values from a column.

My url is ".../NewForm.aspx?Id Pc={@Id_x0020_Pc}"
(FieldTitle="Id Pc" FieldName="Id_x0020_Pc")

My script is ->

_spBodyOnLoadFunctionNames.push("fillDefaultValues");
function fillDefaultValues(){
var qs=location.search.substring(1,location.search.length);
var args=qs.split("&");
var vals=new Object();
for (var i=0; i<args.length;i++){
var nameVal=args[i].split("=");
var temp=unescape(nameVal[1]).split('+');
nameVal[1]=temp.join('');
vals[nameVal[0]]=nameVal[1];
}
var title=vals["Id_x0020_Pc"];
if(title==undefined)
return;
var theSelect=getTagFromIdentifierAndTitle("select","Lookup","Id_x0020_Pc");
if(theSelect==null){
var theInput=getTagFromIdentifierAndTitle("input","","Id_x0020_Pc");
if(theInput==null){
return;
}
theInput.value=title;
document.getElementById(theInput.id).readOnly=true;
}
else{
theSelect.value=title;
document.getElementById(theSelect.id).readOnly=true;
}

function getTagFromIdentifierAndTitle(tagName,identifier,title){
var len=identifier.length;
var tags=document.getElementsByTagName(tagName);
for(var i=0;i<tags.length;i++){
var tempString=tags[i].id;
if(tags[i].title==title && (identifier=="" ||
tempString.indexOf(identifier)==tempString.length - len)){
return tags[i];
}
}
return null;
}


what did I do wrong? :?

Anonymous said...

Hi, I tried using the script to select option using javascript, and yeah its working. But the problem is: the list itself is not updating once I override the selected value. It was just literally selected :3

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Subscribe feeds rss Recent Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Blog Archive

My Blog List

Followers

Links