I have a webpart with list B put in a displayform of an item of list A . Lets assume its for adding grocery in your basket where list A contains baskets and list B groceries with a column associated with basket ID.

Therefore everytime when you open displayform of a basket you will have a list of groceries in a webpart and you can add or edit your groceries.

I achieved this by passing a parameter of ID so if filters the view. Now each time you click on new item to add groceries in the basket you are displaying you still need to manually write the basket ID in order for everything to work.

I would like to do it automatically so I thought that if I display newform in a dialog the URL will stay the same so I would be able to get ID of the basket from the URL using SPservices script and putting it in the field.

The code itself works when i test it on just a simple form, so it gets the ID and puts it in the field, but it STOPS WORKING and gives UNDEFINED when i actually try running it in the dialog box so it can get ID of the basket displayed underneath. Any ideas as to why that happens?

Here's my code:

    $(document).ready(function() {
    var queryStringVals = $().SPServices.SPGetQueryString();
    var lastID = queryStringVals["ID"];
    $("input[title='field']").val(lastID);   };

Please try changing the Query string parameter to Something not 'ID',I think the name ID resulting the conflict.

| improve this answer | |
  • I believe the function SPGetQueryString needs to have "ID" as a parameter in order to retrieve value after 'ID=' in the url? – Kloggy Aug 29 '17 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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