Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lachlann 344 posts 626 karma points
    Apr 19, 2012 @ 13:14
    Lachlann
    0

    Empty Record.Id

    hey there,

    I am making some edits to the code for submitting contour forms RESTfully and I am looking to return the record GUID in the JSON response from the CreateRecord function.

                        if (numberOfErrors == 0)
    {
    var record = recordService.Record;
    var recordGuid = record.Id;
    record.IP = userIpAddress;
    record.UmbracoPageId = nodeId;
    recordStorage.InsertRecord(record, form);

    foreach (var f in recordService.Form.Pages[formStep].FieldSets[0].Fields)
    {
    var field = f;
    var currentFieldValue = fieldValues[field.Caption];

    if (GetFieldType(field) == "CheckBox")
    {
    currentFieldValue = string.IsNullOrEmpty(currentFieldValue) ? "False" : "True";
    }

    if (GetFieldType(field) == "DatePicker" && string.IsNullOrEmpty(currentFieldValue))
    continue;

    var key = Guid.NewGuid();
    var recordField = new RecordField
    {
    Field = field,
    Key = key,
    Record = record.Id,
    Values = new List<object> { currentFieldValue }
    };

    using (var recordFieldStorage = new RecordFieldStorage())
    recordFieldStorage.InsertRecordField(recordField);

    record.RecordFields.Add(key, recordField);

    }
    recordService.Submit();
    recordService.SaveFormToRecord();

    var successString = "{ \"message\": " + recordService.Form.MessageOnSubmit + ", \"recordGuid\": " + record.Id.ToString() + " }";

    jsonErrorString = recordGuid.ToString(); //successString;

    // jsonErrorString = recordService.Form.MessageOnSubmit;
    }

    In the above section of code you can see that if there are no errors it will create a new cord I also set a variable called recordGuid.

    the problem is the Guid seems to return 0000-00000-0000-000 (i,e, an empty guid) I have tried tracing this both when the record is created and after it the record service saves form but I still get an empty value.

    Any ideas?

    Cheers

    L

  • Lachlann 344 posts 626 karma points
    Apr 19, 2012 @ 13:29
    Lachlann
    0

    SORRY! my bad I wasn't returning the JSON string I thought I was.

    Works fine

     

    L

Please Sign in or register to post replies

Write your reply to:

Draft