1

I'm using SharePoint online and have a SharePoint-hosted app.

I have a page with a question form that send data in to Sharepoint using listItem.set_item('GEN_1_blabla', $('#GEN_1').val());

Now in my list when you click on an item it's open in DispForm.aspx and in there i have my question page again how can i get it to load the information to the textboxes in my question page.

I have read about get_fieldValues() but dont know how to get it to work.

var appContext, hostweburl, hostContext, parentWeb, list;

appContext = new SP.ClientContext.get_current();
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
hostContext = new SP.AppContextSite(appContext, hostweburl);
parentWeb = hostContext.get_web();
list = parentWeb.get_lists().getByTitle("CoromaticIFU");

$(document).ready(function () {
    $("#tabs").tabs();
    $(document).tooltip();
    $('#GEN_4').datepicker({ dateFormat: 'yy-mm-dd' }).val();
    $('#save').click(setItems);
});

function setItems() {
   var listCreationInformation = new SP.ListItemCreationInformation(), listItem = list.addItem(listCreationInformation);

    listItem.set_item('GEN_1_Sum_Scope_Assigment', $('#GEN_1').val());
    listItem.set_item('GEN_1_Sum_Scope_Assigment_D', $('#GEN_1_D').val());
    listItem.set_item('GEN_2_CRMname', $('#GEN_2').val());
    listItem.set_item('GEN_2_CRMname_D', $('#GEN_2_D').val());
    (etc)
    listItem.set_item('GEN_19_BYGG_GOLV', $('input[name="GEN19"]:checked').val());
    (etc)
    listItem.set_item('DRI_6_Personnel_Servicetype', $("#DRI_6 option:selected").text());
    (etc)
    listItem.update();

    appContext.load(listItem);
    appContext.executeQueryAsync(function (success) { alert("Din sparning lyckades!"); }, function (sender, args) { alert('Error:' + args.get_message()); });
}

I have tried this with get_fieldValues

function getItems()
{
    listItem.get_fieldValues('GEN_1_Sum_Scope_Assigment', $('#GEN_1').val());
    listItem.update();

    appContext.load(listitem);
    appContext.executeQueryAsync(function (success) { alert("lyckades!"); }, function (sender, args) { alert('Error:' + args.get_message()); });

}
  • listItem.get_fieldValues() returns the JSON containing the item values as {internalname1:value1,internalname2:value2,....} – sekhar Oct 29 '14 at 8:57
  • ok how can i write the code to get to work? – linkan94 Oct 29 '14 at 9:16
1

Answer:

var item = list.getItemById(92);

$(document).ready(function () {

appContext.load(item);
appContext.executeQueryAsync(function () {
   $('#GEN_1').val(item.get_fieldValues().GEN_1_Sum_Scope_Assigment);
    $('#GEN_1_D').val(item.get_fieldValues().GEN_1_Sum_Scope_Assigment_D);
    $('#GEN_2').val(item.get_fieldValues().GEN_2_CRMname);
    $('#GEN_2_D').val(item.get_fieldValues().GEN_2_CRMname_D);
}, function (sender, args) { alert('Error:' + args.get_message()); });

)};

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.